1

Thanks for taking the time to read my question.

I have a problem adding the message and message status blocks in my content region using Drupal 9. I'm using a custom theme.

The blocks are simply not displayed. They are not even added to the DOM.

Here is my block configuration : https://i.stack.imgur.com/90fkY.jpg (Sorry, it's in French. The two blocks are underlined in red)

And the configuration of each block : https://i.stack.imgur.com/lq6jK.jpg and https://i.stack.imgur.com/eUScy.jpg (again, in French, but there are no restriction on page, role or type of content - it should appear everywhere)

I found these solutions online :

1 - https://www.drupal.org/forum/support/theme-development/2016-03-08/d8-any-reason-why-blocks-arent-renderingdisplaying

I tried uninstalling my theme, clearing the cache, reinstalling my theme but it doesn't work. The blocks did not appear in the Bartik theme either.

2 - https://www.drupal.org/forum/support/post-installation/2018-09-23/new-blocks-not-displaying

I tried adding a simple test block, it appears normally.

I tried displaying a test message using $this->messenger()->addMessage("test"); in a module to be sure there was something to display but with no success.

I'm not sure if it helps but here is my page.twig template :

<header aria-label="Site header" class="header" id="header" role="banner">
    <div id='header-content'>
        <div id="header-left">
            {{ page.branding }}
            {{ page.navigation }}
        </div>
        <div id='header-right'>
            {{ page.user_menu }}
            {{ page.search }}
        </div>
    </div>
</header>
<section class="main" id="main">
   <main aria-label="Site main content" class="content" id="content" role="main">
     {{ page.content }}
   </main>
</section>
<footer aria-label="Site footer" class="footer" id="footer" role="contentinfo">
   <div class="footer--top">
     {{ page.footer_first }}
   </div>
   <div class="footer--bottom">
       {{ page.footer_bottom }}
   </div>
</footer>

Does any of you already encountered the problem ? Is there a solution ?

Thanks again !

EDIT

Here is the output from twig debug :

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'block' -->
<!-- FILE NAME SUGGESTIONS:
   * block--messages.html.twig
   x block--system-messages-block.html.twig
   * block--system.html.twig
   * block.html.twig
-->
<!-- BEGIN OUTPUT from 'core/modules/system/templates/block--system-messages-block.html.twig' -->
<div data-drupal-messages-fallback class="hidden"></div><span data-big-pipe-placeholder-id="callback=Drupal%5CCore%5CRender%5CElement%5CStatusMessages%3A%3ArenderMessages&amp;args%5B0%5D&amp;token=_HAdUpwWmet0TOTe2PSiJuMntExoshbm1kh2wQzzzAA"></span>

<!-- END OUTPUT from 'core/modules/system/templates/block--system-messages-block.html.twig' -->

This suggests that the \Drupal::messenger()->addMessage(); does not output any message.

A strange thing I noticed testing with a FormBase class is that the Drupal\Core\Form\FormStateInterface::setErrorByName() method is working fine. A message is being displayed and the twig debug output becomes

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'block' -->
<!-- FILE NAME SUGGESTIONS:
   * block--cessoc-messages.html.twig
   x block--system-messages-block.html.twig
   * block--system.html.twig
   * block.html.twig
-->
<!-- BEGIN OUTPUT from 'core/modules/system/templates/block--system-messages-block.html.twig' -->
<div data-drupal-messages-fallback class="hidden"></div>

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'status_messages' -->
<!-- BEGIN OUTPUT from 'core/modules/system/templates/status-messages.html.twig' -->
<div data-drupal-messages>
  <div role="contentinfo" aria-label="Message d'erreur">
          <div role="alert">
              <h2 class="visually-hidden">Message d'erreur</h2>
              The title must be at least 5 characters long.
              </div>
      </div>
</div>

<!-- END OUTPUT from 'core/modules/system/templates/status-messages.html.twig' -->



<!-- END OUTPUT from 'core/modules/system/templates/block--system-messages-block.html.twig' -->
  • Try creating file `block--system-messages-block.html.twig` in your custom theme with any text and check if it is displayed. – Kien Nguyen Feb 03 '21 at 02:46
  • Yes it is working, Thank you ! What should I put in this file to display the system messages ? –  Feb 03 '21 at 15:41
  • So there is no problem with your region. Now delete the file you just created (remember to flush cache) and enable twig debug. Then find out if template `block--system-messages-block` has been overriden somewhere? – Kien Nguyen Feb 04 '21 at 02:34
  • I edited my post to add some code regarding what you said in your previous comment. I think the problem comes from the \Drupal::messenger()->addMessage(); method which is weird because it's working fine in the "administration" part of my website. Thanks for your suggestion ! –  Feb 04 '21 at 13:19
  • 1
    It looks like that the module `BigPipe` can't replace "data-big-pipe-placeholder-id" `span` by the actual content of the block. I think this could be a javascript related problem. Are you available to chat now? – Kien Nguyen Feb 04 '21 at 15:24
  • I'm sorry I just left work (It's work related) and won't be able to access my code until monday. I'm going to look at the module you mentioned this week end and will check with you monday if you're available to chat and if it's no too much trouble for you. Thanks again ! –  Feb 04 '21 at 15:54
  • This was indeed a BigPipe / js issue. I solved it, thanks for the tip ! –  Feb 11 '21 at 13:51

1 Answers1

1

My problem is solved !

Like Kien Nguyen suggested, this was an issue caused by the BigPipe module not filling the message block with the status messages.

Apparently, this was because my theme contained a jQuery.js file which was outdated. I deleted it and everything work fine now.