bnomei / kirby3-autoid

Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.
https://forum.getkirby.com/t/kirby3-autoid-plugin/23572
MIT License
80 stars 8 forks source link

searchForTemplate() returns Kirby\Cms\Collection instead of Kirby\Cms\Pages #80

Closed iskrisis closed 2 years ago

iskrisis commented 2 years ago

I thought the use of Collection instead of Pages was because of handling of drafts. It seems the searchForTemplate gathers drafts but they are null in the collection anyway. The problem with collection is that you cant use listed/unlisted and some other methods.

https://github.com/bnomei/kirby3-autoid/blob/76372d3b8d6bab5f4c7188944f48e54f9eb33b51/classes/AutoIDDatabase.php#L111-L116

Change could just be

$results = new \Kirby\Cms\Pages;
$str = "SELECT * FROM AUTOID WHERE template = '${template}'" . $rootId;
foreach ($this->database->query($str) as $obj) {
    $results->add((new AutoIDItem($obj))->toObject());
}
return $results;

Not sure how Drafts should be handled - Kirby\Cms\Pages seem to be really pesky about including drafts because they have no id. But i think the returned object from searchByTemplate/findByTemplate should be Kirby\Cms\Pages.

iskrisis commented 2 years ago

@bnomei i would PR this (i mean its in the comment) just don't know your opinion about this. Sorry i didn't want to bring you more work.

bnomei commented 2 years ago

i will probably take a look next week. no problem