localgovdrupal / localgov_subsites_extras

GNU General Public License v2.0
0 stars 0 forks source link

Can't add a <nolink> menu item #20

Open andybroomfield opened 1 month ago

andybroomfield commented 1 month ago

When adding a <nolink> menu item to the subsites menu, the subsites menu causes a WSOD.

TypeError: Drupal\localgov_subsites_extras\Service\SubsiteService::walkMenuTree(): Argument 1 ($node) must be of type Drupal\node\NodeInterface, null given, called in /app/web/modules/contrib/localgov_subsites_extras/src/Service/SubsiteService.php on line 102 in Drupal\localgov_subsites_extras\Service\SubsiteService->walkMenuTree() (line 88 of modules/contrib/localgov_subsites_extras/src/Service/SubsiteService.php).

What should happen: Menu displays with the nolink option

andybroomfield commented 1 month ago

It's to do with the way this module tries to discover the subsite homepage. https://github.com/localgovdrupal/localgov_subsites_extras/blob/2b61f1ef6d073196bdaf6feeafc0a0b0e4e2f46f/src/Service/SubsiteService.php#L85-L106

We can't assume a menu link will always be a node, It could also be a view, custom controller, form, external or <nolink> which is a common way of adding menu sections. Instead we should try to use the menu link and check if it's a node, and if not, continue up to the next level.

rupertj commented 1 month ago

I'm pretty sure that https://github.com/localgovdrupal/localgov_subsites_extras/pull/16 will fix this.