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
Prevent $pages->add() from silently breaking when adding invalid entries #1890
Comments
I wouldn't expect that a If you need |
@neildaniels hm, I agree, that actually does make more sense. In that case, Edit: It also breaks silently when you do: $pages->add([
'foo' => 'bar'
]);
Then |
I actually like the current behavior, because I can do things like |
Well, you need to check for if ($myPage = $field->toPage()) {
echo $myPage->url();
} Having to check for Besides, I'm not sure that putting off handling of invalid values to underlying APIs is a good pattern. It could lead to many unexpected behaviors in my opinion. That might be OK for other cases, but for this one, as you've already said, a |
I think we found a good solution for it. You can still pass null or false and those values are simply ignored, but when you try to pass an invalid object, which is not a Page, an exception is thrown. |
Describe the bug
I want to create a pages collection containing ModelWithContent entries. However, if I add the
$site
, I run into problems, probably because it doesn't have an ID.I know I could use
Kirby\Cms\Collection
, but I need theindex()
method which is only present inKirby\Cms\Pages
.To Reproduce
To reproduce the behavior:
Expected behavior
The collection should contain the Site.
Kirby Version
3.2.0
Additional context
I get that this is kind of an edge case, but Kirby is all about flexibility. Since both Site and Page extend ModelWithContent, it is expected that you can create a group of ModelWithContent that can contain both of these child classes.
My use case is for a plugin - the user can provide a Pages object and anything inside is exported. He might want to include the Site data there or he might not.
Note: It works OK if I use
prepend()
/append()
instead ofadd()
. Judging by the source code, it may be because Site doesn't have an ID. If that's the problem, then my proposal is to give it an ID of<site>
or something similar.The text was updated successfully, but these errors were encountered: