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
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
-
Have you tried?
β’router:cache:warm-up:backoffice
β’cache:empty-all
0 -
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βοΈ - Guardians (admin)
Have a look at src/Spryker/Zed/ZedNavigation/ZedNavigationConfig.php
public function getMergeStrategy(): string
- by default this method is overridden on project level0 -
@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 berouter:cache:warm-up
because adding the:backoffice
suffix caused it to give me errors. Thanks for the suggestion though!0 -
@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.0 -
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 thePyz/Zed/*
Namespace? I know we changed a config option to allow us to use another namespace for our module. Maybe the search fornavigation.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.0 -
Tried moving my test module into
Pyz/Zed/*
, renamed the appropriate classes, and set breakpoints in theXxxConfig.php
file but those breakpoints never get hit, so it seems like my Config file is never executed. I can set breakpoints in thePyz/Zed/ZedNavigation/ZedNavigationConfig.php
and those get hit, so I know breakpoints are working on my configuration.0 -
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!0 -
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βοΈ - 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?
0 -
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
isindexAction()
, which seems to work fine withindex.twig
to display any text content I substitute in when loading the page manually.0 -
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>
0 -
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 withconsole cache:empty-all
and refreshed by browser page to see the error.0 -
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.0 -
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βοΈ - 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.php
public 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';
0 -
@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 inconfig/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 toFULL_MERGE_STRATEGY
inZedNavigationConfig
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 itemI 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'snavigation.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!
0 -
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,084 βοΈ - 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 π
0 -
@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!
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K π Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random