Skip to content

Unexpected behaviour for Language::isLast() #7857

@rasteiner

Description

@rasteiner

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions