Skip to content

BUG: Neos.Neos:MenuItem state is accessed differently than documented. #5732

@jonaphil

Description

@jonaphil

Is there an existing issue for this?

  • I have searched the existing issues

There already was a bugreport on this topic, but it was closed by the opener shortly after without a reply from the core-team: #5712

I still consider this a bug, because it is a mismatch between Documentation and current implementation.

Current Behavior

To access the state as a string of a MenuItem I have to access it via item.state.value

                items = Neos.Neos:MenuItems
                
                renderer = afx `
                    <Neos.Fusion:Loop items={props.items} @children='itemRenderer'>
                         <Customer.Base:Components.Organisms.MainNavigation.ItemList.Item
                             label={item.label}
                             state={item.state.value}
                             link={item.uri}
                             subItems={item.subItems} />

The Documentation states that item.state returns a string: https://neos.readthedocs.io/en/9.2/References/NeosFusionReference.html#menuitems-item-properties

Expected Behavior

I can assess the state as string via item.state, like stated in the Documentation.

                items = Neos.Neos:MenuItems
                
                renderer = afx `
                    <Neos.Fusion:Loop items={props.items} @children='itemRenderer'>
                         <Customer.Base:Components.Organisms.MainNavigation.ItemList.Item
                             label={item.label}
                             state={item.state}
                             link={item.uri}
                             subItems={item.subItems} />

Steps To Reproduce

Use the Fusion Objects as above.

Environment

- Flow: 9.1.0
- Neos: 9.1.1
- PHP: 8.3

Anything else?

The Documentation states that the state of a MenuItem is of type string: https://neos.readthedocs.io/en/9.0/References/NeosFusionReference.html#menuitems-item-properties
This is also the behavior I would expect from the property.

On the contrary the current implementation returns a backed enum as state: https://neos.github.io/neos/9.0/Neos/Neos/Fusion/MenuItem.html#method_getState .

If I understand it correctly (please correct me if I'm wrong), the MenuItem-Object has getters for all values which can be accessed in fusion. (Which confused me in the first place, because in the code documentation there are a lot of links to methods, which don't exist directly in the code. listed Methods here: https://neos.github.io/neos/9.0/Neos/Neos/Fusion/MenuItem.html, aren't present here: https://github.com/neos/neos/blob/9.0/Classes/Fusion/MenuItem.php)

I would expect something like the following to solve the problem. So in Fusion the state can be accessed as a string, but in PHP, it is still possible to access the $state as backed enum MenuItemState.

Neos.Neos/Classes/Fusion/MenuItem.php
<?php
//... skip lines 2 - 43
    public function getUri(): ?string
    {
        return $this->uri;
    }

    public function getState(): ?string
    {
        if (isset($this->state)) {
            return $this->state->value;
        }
        return null;
    }
}

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