Problem/Motivation
When saving a node associated with an OG menu instance, the OgMenuBlock Plugin throws an error at the first load since the property does not exists yet. Upon reload, the property was cached and the page render as expected.
Steps to reproduce
Setup
- Drupal 10.1.x
- PHP 8.2.3
- Organic groups 8.x-1.0-alpha10
Create a new node that's associated with an OG and add it to the Group's menu. Save the node and you should get the following error:
The website encountered an unexpected error. Please try again later.
Error: Typed property Drupal\og_menu\Plugin\Block\OgMenuBlock::$menuName must not be accessed before initialization in Drupal\og_menu\Plugin\Block\OgMenuBlock->getMenuName() (line 315 of modules/contrib/og_menu/src/Plugin/Block/OgMenuBlock.php).Proposed resolution
initialize the $menuName property in the constructor of the OgMenuBlock class
Remaining tasks
Add code to src/Plugin/Block/OgMenuBlock.php
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|
Issue fork og_menu-3392055
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
baroneComment #3
olivierg commentedHi,
the patch does not work correctly cause the getMenuName function doesn't get the name you already defined as blank in the constructor.
So we have to change the getMenuName function in order to check menuName is not blank.
Comment #4
baroneHi @OliverG thanks for the replay and for the patch. I'm adding a conditional check to avoid getting the error of calling ->id() on NULL. If this one works for you we may get this issue closed!
Comment #5
dimilias commentedI am making a slight change to check for the ID, not just the entity. The reason is that OG menu seems to break the layout builder which passes as context an entity without an ID.
Comment #6
dimilias commentedFixed a php sniff.
Comment #7
alorencI think we need to combine checks from #4 and #5, check if entity and id is not empty
Comment #9
claudiu.cristeaHide old patches
Comment #10
claudiu.cristeaLooks good
Comment #12
claudiu.cristeaThank you!
Comment #13
claudiu.cristeaReleased in 2.0.0-alpha3