-
-
Notifications
You must be signed in to change notification settings - Fork 184
Description
Description
The current implementation of $language->isLast() checks if "only one Language is configured in Kirby", and not whether "the language object is the last one in a collection".
Expected behavior
I would expect the isLast function to work like the isFirst function (accept an optional collection and check if it is the first / last object in it). This allows us, for example, to apply specific styles to a language switcher.
Additional context
Current implementation:
https://github.com/getkirby/kirby/blob/5.2.1/src/Cms/Language.php#L341-L347
The function implementation was introduced by the commit 597ccca.
In which "is last" assumes the meaning of "the sole remaining language when deleting them", which in my opinion is a bit unexpected given that the object in kirby is often accessed through a Languages collection which is sortable.
Your setup
Kirby Version
5.2.1
Workaround
I can check if a language is the last object in the collection by using the Collection method ->last() and compare it to the language:
$langsCollection->last()->is($lang)Proposal
Maybe we can introduce something like a isSole or isLone or hasNoSiblings or something to the HasSiblings trait which does what the current $language->isLast() does.