Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't a section both have hasUrls set to false and a template configured? #3830

Closed
pieterbeulque opened this issue Feb 12, 2019 · 5 comments

Comments

@pieterbeulque
Copy link

if ($siteSettingsRecord->hasUrls = $siteSettings['hasUrls']) {
$siteSettingsRecord->uriFormat = $siteSettings['uriFormat'];
$siteSettingsRecord->template = $siteSettings['template'];
} else {
$siteSettingsRecord->uriFormat = $siteSettings['uriFormat'] = null;
$siteSettingsRecord->template = $siteSettings['template'] = null;
}

I'm having trouble using Craft::$app->sections->saveSection($section) to create a section with settings configured like this:

new Section_SiteSettings([
  'siteId' => $site->id,
  'hasUrls' => false,
  'uriFormat' => 'IGNORE', // This is neccessary to skip validation errors, somehow
  'template' => 'myTemplate',
]);

Am I trying to do something that I shouldn't try to do or is this a bug?

@pieterbeulque
Copy link
Author

pieterbeulque commented Feb 12, 2019

It worked with these Section_SiteSettings. I found the answer in #2525.

new Section_SiteSettings([
  'siteId' => $site->id,
  'hasUrls' => true,
  'uriFormat' => '__home__', // This is a magic keyword, apparently
  'template' => 'myTemplate',
]);

@brandonkelly
Copy link
Member

If you don’t want the section to have URLs, then you should just leave the uriFormat set to null (or don't include the line at all).

@pieterbeulque
Copy link
Author

@brandonkelly, that's what I thought, but that threw a validator error saying uriFormat cannot be blank.

@brandonkelly
Copy link
Member

@pieterbeulque The only time uriFormat is required is if the section type is a Single, or if hasUrls is true.

@pieterbeulque
Copy link
Author

OK, then it threw the validation error because it was a single.

Thanks for clarifying this, @brandonkelly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants