What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello! I'm trying to add a navigation entry link to the Zed Backoffice left navigation from a module

U049953K1LJ
U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

Hello!
I'm trying to add a navigation entry link to the Zed Backoffice left navigation from a module. I can add an entry into the global config/Zed/navigation.xml and the changes shows up fine, just as I would expect. But creating a navigation.xml in my project module at Communication/navigation.xml does not seem to affect the left navigation at all. I have my Communication/Controller/IndexController.php working and able to run PHP code and generate output, so I know the module itself is working. This is basically a hello-world module, I just can't figure out why it's not loading my navigation.xml.

It seems that the online documentation for Zed's backoffice navigation is rather sparse - I found a total of 2 pages discussing it.
Any help would be appreciated!

Comments

  • Chemaclass
    Chemaclass Tech Lead Spryker Solution Partner Posts: 213 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited November 2022

    Have you tried?
    β€’ router:cache:warm-up:backoffice
    β€’ cache:empty-all

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,051 βš–οΈ - Guardians (admin)

    Have a look at src/Spryker/Zed/ZedNavigation/ZedNavigationConfig.php public function getMergeStrategy(): string - by default this method is overridden on project level

  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

    @U015S0C0V29 I assumed I needed to try those as arguments to the console command. I just tried both again to be sure, but the results did not change. Also I think the first one should be router:cache:warm-up because adding the :backoffice suffix caused it to give me errors. Thanks for the suggestion though!

  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

    @florian.scholz I saw that function, but I don't think I fully understand the purpose of that function, or how it relates to adding new entries to the navigation. Nonetheless, I tried returning both static::*__MERGE__STRATEGY constants, with no variation in the navigation output.

  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

    I'm pretty sure my issue revolves around it somehow not loading the navigation.xml, but maybe it's something else. Does my module need to under the Pyz/Zed/* Namespace? I know we changed a config option to allow us to use another namespace for our module. Maybe the search for navigation.xml isn't searching the alternate path? I can trace with xdebug, but I don't know where to look for the code that does the path search.

  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

    Tried moving my test module into Pyz/Zed/*, renamed the appropriate classes, and set breakpoints in the XxxConfig.php file but those breakpoints never get hit, so it seems like my Config file is never executed. I can set breakpoints in the Pyz/Zed/ZedNavigation/ZedNavigationConfig.php and those get hit, so I know breakpoints are working on my configuration.

  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

    If I modify my navigation.xml to have mismatched start/end tags, I see a parse error when loading the page. So that means the XML is being loaded after all, but perhaps just not used in the actual navigation building process? I suppose on the positive, I have a stack trace now indicating where it's being loaded from!

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,051 βš–οΈ - Guardians (admin)

    Ok, can you post your navigation.xml and where exactly you put it? - also maybe your module where the config is not being loaded?

  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited November 2022

    The latest module base is src/Pyz/Zed/Briannavtest, and from there, I have 3 files in the module:
    β€’ Communication/Controller/IndexController.php
    β€’ Communication/navigation.xml
    β€’ Presentation/Index/index.twig
    This is basically the "Hello World" module with the addition of the navigation.xml.

    The only method defined in IndexController.php is indexAction(), which seems to work fine with index.twig to display any text content I substitute in when loading the page manually.

  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

    Here's my navigation.xml:

    <?xml version="1.0"?>
    <config>
        <briannavtest>
            <label>Brian NAV TEST Module Label</label>
            <title>Brian NAV TEST Module Title</title>
            <bundle>briannavtest</bundle>
            <controller>index</controller>
            <action>index</action>
            <icon>fa-wrench</icon>
            <visible>1</visible>
            <pages>
                <greeter>
                    <label>Brian NAV TEST Greeter</label>
                    <title>Brian NAV TEST Greeter</title>
                    <bundle>briannavtest</bundle>
                    <controller>index</controller>
                    <action>index</action>
                    <visible>0</visible>
                </greeter>
            </pages>
        </briannavtest>
    </config>
    
  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited November 2022

    To make it error out, I changed the first <briannavtest> tag into <XXXbriannavtest> and left the ending tag as it was (creating the mismatch, and hence the parse error). I then cleared the cache with console cache:empty-all and refreshed by browser page to see the error.

  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

    The file that isn't loading was at: src/Pyz/Zed/Briannavtest/BriannavtestConfig.php and had the following content:

    <?php
    
    namespace Pyz\Zed\Briannavtest;
    
    use Spryker\Zed\ZedNavigation\ZedNavigationConfig as SprykerZedNavigationConfig;
    
    class BriannavtestConfig extends SprykerZedNavigationConfig
    {
        public function getMergeStrategy(): string
        {
            //user_error("Briandebug Exception");
            return static::BREADCRUMB_MERGE_STRATEGY;
            //return static::FULL_MERGE_STRATEGY;
        }
    }
    

    I even tried seeing if generating an error there would show up, but the user_error() was never triggered, nor were breakpoints that I set in that function, which is why I'm assuming isn't being executed.

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,051 βš–οΈ - Guardians (admin)

    Sorry for the late response, everyone is catching a cold right now πŸ™ˆ

    Your getMergeStrategy()`` is never being used because it is the config file of your current module. You need to override the src/Pyz/Zed/ZedNavigation/ZedNavigationConfig.phppublic function getMergeStrategy(): string` with the strategy you want.

    Also have a look at the hints in the file src/Spryker/Zed/ZedNavigation/ZedNavigationConfig.php :

    /**
     * Specification:
     *  - Strategy by which root navigation elements are being merged with core navigation elements.
     */
    public const FULL_MERGE_STRATEGY = 'fullMergeStrategy';
    
    /**
     * Specification:
     *  - Strategy by which root navigation elements are being merged with core navigation elements excluding first and second level.
     */
    public const BREADCRUMB_MERGE_STRATEGY = 'breadcrumbMergeStrategy';
    
  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

    @florian.scholz Thanks for the response. I understand what you're saying about why the function isn't being used.

    I still wasn't quite understanding how navigation.xml was being used within Spryker because there were many modules that have this file, and there's also a global in config/Zed/navigation.xml, yet it seems that only the global one was actually used for rendering the left navigation.

    I was thinking: Why are the module-level files there, if not to populate the navigation? I also couldn't imagine that adding each module's navigation entries requires manually editing the global configuration each time.

    I figured that getMergeStrategy() would be the function to determine how the XMLs were merged, but changing to FULL_MERGE_STRATEGY in ZedNavigationConfig triggered an exception for me:

    Location: /vendor/spryker/zed-navigation/src/Spryker/Zed/ZedNavigation/Business/Model/Formatter/MenuFormatter.php:186
    Exception: Spryker\Zed\ZedNavigation\Business\Exception\ZedNavigationXmlException
    Message: "label" or "title" is missing for navigation menu item

    I traced in, and found both the "label" and "title" were null. I found this was a side effect from incorrect definitions in the navigation.xml of other modules we had loaded. After cleaning up those issues by adding the expected lines, I was able to see my module's navigation.xml content loading on the left navigation as expected!

    So thanks very much for your help in discovering this issue! This effectively solves my problem entirely, and I now have a much better understanding of how this subsystem works!

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,051 βš–οΈ - Guardians (admin)

    Glad that I could guide you. Can you maybe tell me which other navigations you had to adjust in order to make it work? Sounds like a bug to me πŸ™ˆ

  • U049953K1LJ
    U049953K1LJ Posts: 14 πŸ§‘πŸ»β€πŸš€ - Cadet

    @florian.scholz Sorry for the delayed response. Honestly, it was internally developed modules in our installation, not any public modules. So you're right in the fact that it was a bug, but we had to fix the bugs internally πŸ™‚ Thanks again for your help!