Problem/Motivation
On a site with the Menu Block (menu_block) module installed, the following WSOD occurs:
The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\menu_block\Plugin\Block\MenuBlock::getPlugin() in tooltip_block_view_alter() (line 47 of modules/contrib/tooltip/tooltip.module).
tooltip_block_view_alter(Array, Object, NULL) (Line: 562)
Drupal\Core\Extension\ModuleHandler->alter('block_view', Array, Object) (Line: 214)
Drupal\block_field\Plugin\Field\FieldFormatter\BlockFieldFormatter->viewElements(Object, 'en') (Line: 89)
Drupal\Core\Field\FormatterBase->view(Object, 'en') (Line: 265)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 340)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 282)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 18)
Drupal\paragraphs\ParagraphViewBuilder->buildMultiple(Array) (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 788)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 374)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 68)
__TwigTemplate_07198e4d4bb10951c4ebe2ebad4b8063->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('core/themes/classy/templates/field/field.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('field', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 75)
__TwigTemplate_ae29f2bb7f214e7e8cb502dc16917ad8->block_paragraph(Array, Array) (Line: 182)
Twig\Template->displayBlock('paragraph', Array, Array) (Line: 58)
__TwigTemplate_ae29f2bb7f214e7e8cb502dc16917ad8->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/custom/cityofhope/templates/paragraph/paragraph--left-nav-columns.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('paragraph', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 446)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 446)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 80)
__TwigTemplate_5fd637efe161c1d93484c88534798b7b->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/contrib/bazo/templates/node/node.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 243)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 713)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
- Install the menu_block and tooltip modules.
- Create (or go to) a page with a menu_block on it.
- The site will WSOD instead of load the page.
Proposed resolution
The menu_block module doesn't have the getPlugin method. However, both menu_block and block modules have getPluginId methods. I suggest replacing the method call to getPlugin in tooltip.module with a call to getPluginId.
Remaining tasks
Patch to be submitted.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3341714-4.patch | 1001 bytes | nhanlq@outlook.com |
| #3 | 3341714-3.patch | 974 bytes | jsutta |
Issue fork tooltip-3341714
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
jsutta commentedPatch attached.
Comment #3
jsutta commentedAdding a new version of the patch after my coworker pointed out that getPluginId will always return a string, whereas getPlugin returns a block. He suggested first making sure the block is an instance of Drupal\block\Entity\Block and modifying the if statement so that if the block exists and is an instance of TooltipBlockPluginInterface, it should evaluate to true. I also corrected the spelling of the word "instantiate" on line 45.
Comment #4
nhanlq@outlook.com commentedHi
I would like add more code from Patch of Jsutta to hide warning when #block is empty
Comment #5
nhanlq@outlook.com commentedComment #7
_tarik_ commentedThe reason for the problem is the wrong object type that we get in the tooltip_block_view_alter function.
This code looks like the author of the code expected to get the object of the class Block of the namespace Drupal\block\Entity.
The previous patches fix only the problem on line 46, but they still can get the issue on line 48, with the uuid() method that doesn't exist in the Drupal\Core\BlockBlockBase or Drupal\tooltip\TooltipBlockBase classes
The solution isn't pretty, and looks like we need to change the way for setting the "data-tooltip-id" attribute to make it more generic
Comment #11
matthieuscarset commentedThank you for reporting this issue and for the fixes provided.
In reply to #7, I'm not sure we can find a more generic way than the block_view_alter. How do you suggest we make sure that the data-tooltip-id attribute exists on the block ?
Meanwhile, I consider that the necessary changes to prevent the WSOD have been merged.
New release coming soon so I mark this issue as fixed.