Skip to content

Prevent $pages->add() from silently breaking when adding invalid entries #1890

@hdodov

Description

@hdodov

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 the index() method which is only present in Kirby\Cms\Pages.

To Reproduce
To reproduce the behavior:

$models = new Kirby\Cms\Pages();
$models->add(site());

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 of add(). 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions