Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293556

Editing menu results in 500 error

$
0
0

Problem/Motivation

Clicking edit icon on menu item in a page's (contrib) tb_megamenu menu block results in progress arrow continuously and browser console show AJAX call had returned HTTP 500. Expanding this shows exception text: 'Object of type ...Entity\Menu cannot be printed.'

Steps to reproduce

Clicking edit icon on menu item in a page's menu block.

To reproduce standalone:
Set up hook_theme() in a test .module and twig template as described in https://www.drupal.org/docs/develop/theming-drupal/twig-in-drupal/create...

Add to test module Controller:

use Drupal\system\Entity\Menu;
....
$m = new Menu(['id'=>'mymenuid', 'label'=>'mymenulabel'], 'menu');
return [
      '#theme' => 'my_template',
      '#test_var' => $m,
    ];

Calling controller will give the:

Exception: Object of type Drupal\system\Entity\Menu cannot be printed. in Drupal\Core\Template\TwigExtension->escapeFilter() (line 459 of core/lib/Drupal/Core/Template/TwigExtension.php). 
__TwigTemplate_570b34ddc31fd2054d7b637ea3a5d243->doDisplay() (Line: 388)
....

Proposed resolution

The Exception is thrown in core/lib/Drupal/Core/Template/TwigExtension.php. This filter looks for a toString() etc method on the Menu entity (in core/modules/system/src/Entity/Menu.php)
Resolve by adding a simple toString() method to Menu entity, returning the label or id property (see patch).
Rerun test above, and you should see

Test twig template!
 
test_var: mymenulabel

Remaining tasks

Apply patch to current and future branches

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 293556

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>