Drupal 9 - 消息和消息状态系统块不显示

问题描述 投票:0回答:2

感谢您花时间阅读我的问题。

我在使用 Drupal 9 在内容区域添加消息和消息状态块时遇到问题。我正在使用自定义主题。

这些块根本不显示。它们甚至没有添加到 DOM 中。

这是我的块配置:https://i.sstatic.net/90fkY.jpg(抱歉,这是法语。这两个块用红色下划线表示)

以及每个块的配置:https://i.sstatic.net/lq6jK.jpghttps://i.sstatic.net/eUScy.jpg(同样是法语,但没有限制在页面、角色或内容类型上 - 它应该出现在任何地方)

我在网上找到了这些解决方案:

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

我尝试卸载我的主题,清除缓存,重新安装我的主题,但它不起作用。这些块也没有出现在 Bartik 主题中。

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

我尝试添加一个简单的测试块,它显示正常。

我尝试使用 $this->messenger()->addMessage("test"); 显示测试消息在模块中以确保有一些内容可以显示,但没有成功。

我不确定它是否有帮助,但这是我的 page.twig 模板:

<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>

你们中有人已经遇到过这个问题吗?有解决办法吗?

再次感谢!

编辑

这是 twig 调试的输出:

<!-- 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' -->

这表明 \Drupal::messenger()->addMessage();不输出任何消息。

我注意到使用 FormBase 类进行测试时发现的一件奇怪的事情是 Drupal\Core\Form\FormStateInterface::setErrorByName() 方法工作正常。正在显示一条消息,twig 调试输出变为

<!-- 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' -->
drupal drupal-theming drupal-themes drupal-9
2个回答
2
投票

我的问题解决了!

就像 Kien Nguyen 所建议的那样,这是由于 BigPipe 模块未用状态消息填充消息块而导致的问题。

显然,这是因为我的主题包含一个过时的 jQuery.js 文件。我删除了它,现在一切正常。


0
投票

如果启用了 BigPipe 模块,则警报消息将无法正确显示,因为

status-messages.html.twig
未呈现。

enter image description here enter image description here

当您卸载 BigPipe 模块时,警报消息正常工作并且

status-messages.html.twig
正在渲染。

enter image description here enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.