Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu validation failure for parent menu under root #54

Open
4 tasks done
robbykrlos opened this issue Sep 26, 2023 · 0 comments
Open
4 tasks done

Menu validation failure for parent menu under root #54

robbykrlos opened this issue Sep 26, 2023 · 0 comments

Comments

@robbykrlos
Copy link

robbykrlos commented Sep 26, 2023

This is a bug.

Prerequisites

  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you check the documentation?
  • Did you perform a cursory search?

Description

Assume you have this scenario:

You have 2 menus:

  • /Administration (so Administration is under root - parentMenu = null)
  • /Help/Administration (so Administration is under Help - parentMenu=Help)

When configuring the enso:cli Menus, you are asked for parentMenu, which accepts nested naming convention.

If you want to target Help.Administration as parentMenu, it will work fine.

But if we target a menu which is under root, and has the same name as another menu used under other parent menu, it will fail the validation Meaning: creating a menu under parentMenu Administration will trigger a warning and will not allow File generation.

image8

This is because, there is no way to name/target the parentMenu "null.Administration", and if only "Administration" is used, then this will be searched in all menu names, thus possibly find more menus and generate the warning.

I've tracked down this issue to vendor/laravel-enso/cli/src/Services/Validators/Menu.php, and it seems to be only a problem on validation and not on the actual functionality of how the migration of "structure" files is processed.

I've temporary fixed this issue by:

private function nestedParentMatches($menu)
    {
        $matches = false;
        $nestedMenu = $menu->name;
        
        //Fix for nested root menu. 
        if($menu->parent_id === null) {
            return "null.{$nestedMenu}" === $this->menu->get('parentMenu');
        }

        while (! $matches && $menu?->parent_id !== null) {
            $nestedMenu = "{$menu->parent->name}.{$nestedMenu}";
            $matches = $nestedMenu === $this->menu->get('parentMenu');
            $menu = $menu->parent;
        }

        return $matches;
    }

allowing the "null" to be mentioned as nested naming.

But this has to be removed afterwards from the migration structure:
Generated:

protected ?string $parentMenu = 'null.Administration';

Fixed:

protected ?string $parentMenu = 'Administration';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant