getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.49k stars 1.4k forks source link

Search for prev/next sibling returns Collection #3396

Open Karmalakas opened 3 years ago

Karmalakas commented 3 years ago

/system/src/Grav/Common/Page/Collection.php::adjacentSibling() may return back the whole Collection if previous or next sibling is not found. All other places in such case expect to return false. system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php::adjacentSibling() defines return types PageInterface|PageCollectionInterface|false, but PageCollectionInterface should not be there as no other method expects to return it. Also naming suggests a PageInterface if found or empty value (null|false) to be returned if not found, but not a collection

mahagr commented 3 years ago

Yup. I have no idea why it does that, but I did add PageCollectionInterface into the return values because it did that for some crazy reason.

CC @rhukster

Karmalakas commented 3 years ago

FYI, I'm already creating a PR for this 😉

mahagr commented 3 years ago

I don't think it will be accepted as I'm pretty sure there was a reason why I didn't fix that.

Karmalakas commented 3 years ago

Still created 🙂 Maybe it'll be a jump-start for Grav team to investigate this

mahagr commented 3 years ago

I checked Flex Pages collections and it already has this behavior. Though it's not really being used, but... I must have been thinking about changing the behavior already.

Karmalakas commented 3 years ago

Yes, elsewhere it's fine. That's why I'm leaning towards fixing page collection too.

praserx commented 12 months ago

Hi, any progress here? I am facing the same issue as @Karmalakas and it is quite annoying. Is there any correct (simple or straightforward) way to get page siblings?

For me, it looks like it is broken, or I am wrong? Or I don't get something important?

Edited: Sorry, bad output during debugging - collections and children itself are ok.