Problem/motivation

Drupal 7 has most global site and page elements hardwired into templates, and gives no control to users to move them around. All the page elements (title, tabs, actions, breadcrumb, messages) are hardwired to core and contrib themes alike. We should stop special-casing these, so they can be moved around and selectively hidden or replaced as needed.

The page element "messages" needs special attention:
1) drupal_get_messages() returns messages only once
2) having block and page element at the same time is fragile
3) this block should use post-render callback to render messages later in page render

Proposed solution

  • Introduce messages block that can be moved around.
  • Remove special case item from themes.
  • Introduce regions as needed to place these blocks.
  • Introduce MessagesBlockPluginInterface, which is implemented by the messages block. Just like we have MainContentBlockPluginInterface. Like the main content, messages are crucial — without messages, Drupal might look broken. By having an interface for the messages block (or alternative messages blocks), we can ensure that messages are present on the page: if the block isn't placed, we automatically provide a fallback.

Related issues

Split off from #507488: Convert page elements (local tasks, actions) into blocks

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because it's an improvement, not a fix.
Issue priority Major because this shouldn't hold up release, but is rather important for the Themer Experience (no more lots of special casing in the page template) and cacheability of Drupal 8.
Prioritized changes The main goal of this issue is performance + TX.
Disruption Only affects custom/contrib code that is using #theme => status_messages today, which will be a handful at most. They'll just have to replace #theme with #type, which is a trivial change (which could also be done by Drupal 8 Module Upgrader).
CommentFileSizeAuthor
#130 interdiff.txt12.52 KBwim leers
#130 convert_messages_page-2289917-130.patch55.59 KBwim leers
#129 Block_layout___Site-Install.png200.2 KBemma.maria
#129 featured-top-with-messages.png56.34 KBemma.maria
#126 convert_messages_page-2289917-126.patch50.35 KBwim leers
#121 convert_messages_page-2289917-121.patch48.25 KBwim leers
#119 interdiff.txt713 byteswim leers
#119 convert_messages_page-2289917-116.patch50.86 KBwim leers
#113 classy-before.png32.96 KBemma.maria
#113 classy-after.png34.91 KBemma.maria
#113 bartik-after.png29.27 KBemma.maria
#113 bartik-before.png28.15 KBemma.maria
#113 bartik-admin-after.png17.38 KBemma.maria
#113 bartik-admin-before.png28.81 KBemma.maria
#113 seven-after.png19.98 KBemma.maria
#113 seven-before.png23.12 KBemma.maria
#111 interdiff-108to111.txt426 bytesdavidhernandez
#111 convert_messages_page-2289917-111.patch47.67 KBdavidhernandez
#108 convert_messages_page-2289917-108.patch47.67 KBemma.maria
#100 interdiff.txt2.32 KBwim leers
#100 convert_messages_page-2289917-100.patch50.45 KBwim leers
#98 interdiff.txt1.77 KBwim leers
#98 convert_messages_page-2289917-98.patch50.22 KBwim leers
#96 interdiff.txt1.19 KBwim leers
#96 convert_messages_page-2289917-96.patch49.99 KBwim leers
#93 interdiff.txt675 byteswim leers
#93 convert_messages_page-2289917-93.patch50 KBwim leers
#92 interdiff.txt8.59 KBwim leers
#92 convert_messages_page-2289917-91.patch49.97 KBwim leers
#89 interdiff.txt1.83 KBwim leers
#89 convert_messages_page-2289917-89.patch50.67 KBwim leers
#87 interdiff.txt4.86 KBwim leers
#87 convert_messages_page-2289917-87.patch49.71 KBwim leers
#85 interdiff.txt5.14 KBwim leers
#85 convert_messages_page-2289917-85.patch45.68 KBwim leers
#79 convert_messages_page-2289917-79.patch41.25 KBwim leers
#77 interdiff.txt13.97 KBwim leers
#77 convert_messages_page-2289917-77.patch29.07 KBwim leers
#71 interdiff.txt11.58 KBwim leers
#71 convert_messages_page-2289917-71.patch28.49 KBwim leers
#70 interdiff.txt4.33 KBwim leers
#70 convert_messages_page-2289917-70.patch39.97 KBwim leers
#65 interdiff.txt11.57 KBwim leers
#65 convert_messages_page-2289917-65.patch36.46 KBwim leers
#63 interdiff.txt6.63 KBwim leers
#63 convert_messages_page-2289917-63.patch38.35 KBwim leers
#60 interdiff.txt3.01 KBwim leers
#60 convert_messages_page-2289917-60.patch33.51 KBwim leers
#58 interdiff.txt2.49 KBwim leers
#58 convert_messages_page-2289917-58.patch31.79 KBwim leers
#57 convert_messages_page-2289917-57.patch32.99 KBwim leers
#54 interdiff-2289917-50-53.txt46.34 KBScionar
#53 convert_messages_page-2289917-53.patch24.47 KBScionar
#50 interdiff.txt9.66 KBlauriii
#50 convert_messages_page-2289917-50.patch30.85 KBlauriii
#47 interdiff.txt1.13 KBlauriii
#47 convert_messages_page-2289917-47.patch23.04 KBlauriii
#44 interdiff.txt789 byteslauriii
#44 convert_messages_page-2289917-44.patch23.11 KBlauriii
#43 convert_messages_page-2289917-42.patch23.72 KBlauriii
#43 interdiff.txt3.5 KBlauriii
#41 interdiff.txt522 byteslauriii
#41 convert_messages_page-2289917-40.patch23.34 KBlauriii
#38 interdiff.txt474 byteslauriii
#38 convert_messages_page-2289917-38.patch22.73 KBlauriii
#32 interdiff-29-32.txt8.12 KBwim leers
#32 interdiff-31-32.txt4.81 KBwim leers
#32 2289917-32-convert-messages-element.patch24.49 KBwim leers
#32 interdiff-29-31.txt5.78 KBwim leers
#32 2289917-31-convert-messages-element.patch23.55 KBwim leers
#29 interdiff.2289917-25-29.txt5.79 KBmanuel garcia
#29 2289917-29-convert-messages-element.patch20.85 KBmanuel garcia
#25 2289917-25-convert-messages-element.patch19.83 KBmanuel garcia
#18 interdiff-2289917-16-18.txt986 bytesrainbowarray
#18 2289917-18-convert-messages-element.patch22.06 KBrainbowarray
#16 interdiff-2289917-11-16.txt431 bytesrainbowarray
#16 2289917-16-convert-messages-element.patch21.66 KBrainbowarray
#11 interdiff-2289917-7-11.txt364 bytesrainbowarray
#11 2289917-11-convert-messages-element.patch21.67 KBrainbowarray
#10 interdiff-2289917-7-10.txt877 bytesrainbowarray
#10 2289917-10-convert-messages-element.patch20.83 KBrainbowarray
#7 interdiff-2289917-5-7.txt546 bytesrainbowarray
#7 2289917-7-convert-messages-element.patch21.69 KBrainbowarray
#5 interdiff-2289917-3-5.txt516 bytesrainbowarray
#5 2289917-5-convert-messages-element.patch21.71 KBrainbowarray
#3 interdiff-2289917-1-3.txt9.96 KBrainbowarray
#3 2289917-3-convert-messages-element.patch21.75 KBrainbowarray
#1 2289917-1-convert-messages-element.patch18.31 KBrainbowarray

Comments

rainbowarray’s picture

Issue summary: View changes
Status: Postponed » Needs review
StatusFileSize
new18.31 KB

Here's the first version of this. Just splitting off messages from the rest of the patch now, with a couple minor tweaks. I'll take care of block__preprocess_page and the post render changes in the next version. The post render version stuff looks sort of complicated, but I'll try to work it out.

Status: Needs review » Needs work

The last submitted patch, 1: 2289917-1-convert-messages-element.patch, failed testing.

rainbowarray’s picture

Status: Needs work » Needs review
StatusFileSize
new21.75 KB
new9.96 KB
  1. Added block_preprocess_page to remove the messages variable from the page template if it exists. This avoids a conflict with the messages block.
  2. webchick wanted to make sure that messages always showed up. So this also prevents the messages block from being disabled, and it also provides a fallback for Bartik and Seven in case the block module is disabled.
  3. Added the post render cache for messages.

Status: Needs review » Needs work

The last submitted patch, 3: 2289917-3-convert-messages-element.patch, failed testing.

rainbowarray’s picture

Status: Needs work » Needs review
StatusFileSize
new21.71 KB
new516 bytes

Trying a different way to remove the page messages variable.

Status: Needs review » Needs work

The last submitted patch, 5: 2289917-5-convert-messages-element.patch, failed testing.

rainbowarray’s picture

Status: Needs work » Needs review
StatusFileSize
new21.69 KB
new546 bytes

I was unsetting the messages region rather than the messages variable.

Taking bets on if this fixes the fails or introduces a whole new slew of them.

Status: Needs review » Needs work

The last submitted patch, 7: 2289917-7-convert-messages-element.patch, failed testing.

rainbowarray’s picture

Well that's unfortunate.

rainbowarray’s picture

Status: Needs work » Needs review
StatusFileSize
new20.83 KB
new877 bytes

Just an experiment here. Checking what happens if I remove the block_preprocess_page function.

rainbowarray’s picture

Found a typo in Bartik's page template that was causing a problem. The interdiff is against patch 7, not patch 10. I don't think this will fix everything, but it might fix some of the fails.

Would be pretty neat if patch 7-11 was the winner. If so, I'm celebrating with a slushie.

The last submitted patch, 10: 2289917-10-convert-messages-element.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 11: 2289917-11-convert-messages-element.patch, failed testing.

rainbowarray’s picture

If I had to bet as to what's going on here, it's this:

There are a lot of tests that add in the block module but still use the testing profile.

The minimal and standard profiles add a messages block to the messages region, but the testing profile does not, because the testing profile does not have blocks.

So if the block module is enabled, but there's no messages block installed with the testing profile, block_preprocess_page will still remove the messages variable from the template.

What would be good is if somehow block_preprocess_page could detect if there was at least one messages block placed in a region. If so, then remove the messages variable. That presumably would help things.

However it doesn't entirely explain all the failures because when block_preprocess_page was removed, there were still 811 fails and 4 exceptions. I'm not clear why.

Maybe I just screwed up the way that the messages post rendering is working.

rainbowarray’s picture

Found another dumb error I made. Ugh. Reworking the patching and testing it.

rainbowarray’s picture

Status: Needs work » Needs review
StatusFileSize
new21.66 KB
new431 bytes

I fixed a typo in the services definition (yay), but when I tested this, messages weren't showing up (boo).

There's a very good chance I'm doing this wrong. If anybody would like to take a look, I'd much appreciate it.

Status: Needs review » Needs work

The last submitted patch, 16: 2289917-16-convert-messages-element.patch, failed testing.

rainbowarray’s picture

Status: Needs work » Needs review
StatusFileSize
new22.06 KB
new986 bytes

timplunkett helped to rework the block_preprocess_page part. This now checks if a messages block is present before removing the messages variable. That should help.

Status: Needs review » Needs work

The last submitted patch, 18: 2289917-18-convert-messages-element.patch, failed testing.

rainbowarray’s picture

Down to 10 test failures. Much, much better.

All the tests that are failing are running on the standard profile, where the messages block is installed, and presumably the messages variable is removed from the page.

So since messages aren't actually showing up in the block, my guess is that the post render cache thing I set up is the problem here. We probably need Wim to figure out what's going wrong. But if you are not Wim, and you want to take a look at this, and you see something that looks off, that's cool too!

dawehner’s picture

Just a quick review ...

  1. +++ b/core/modules/system/src/MessagesPostRenderCache.php
    @@ -0,0 +1,45 @@
    +  /**
    +   * The messages.
    +   * They are stored in a static property so they can appear in multiple blocks.
    +   *
    +   */
    +  protected static $messages;
    +
    ...
    +    if (!isset(static::$messages)) {
    +      static::$messages = drupal_get_messages();
    +    }
    

    Can't you just skip this by using clear_queue=FALSE ?

  2. +++ b/core/modules/system/templates/install-page.html.twig
    @@ -30,7 +30,12 @@
    +      {{ page.messages }}
    

    Does it really make sense to introduce a new region and not reuse the content one?

wim leers’s picture

While working on rerolling #1805054: Cache localized, access filtered, URL resolved, and rendered menu trees — which was green in the middle of June (#1805054-118: Cache localized, access filtered, URL resolved, and rendered menu trees) — I noticed something similar: my #post_render_cache callbacks in renderable arrays for blocks are never invoked! Please check if this is the case here as well; just put a print 'YAY';exit; in the #post_render_cache callback. If the page is rendered incompletely and you see "YAY", then my suspicion is wrong — and I hope I'm wrong.

The reason:

In a nutshell, it's because the theme system/Twig invokes drupal_render() on a copy of the render array, and hence cache tags and #post_render_cache metadata doesn't bubble up as it should […]

There's an issue to fix this over at #2273277: Figure out a solution for the problematic interaction between the render system and the theme system when using #pre_render, and that also contains more info.

Important: this used to work just fine in mid June. So something may have changed block rendering-wise between June 16 and June 22 that causes this. But the overarching problem is #2273277, and that also just needs to be fixed.

rainbowarray’s picture

Time to revive this. Now that post render callbacks should be working correctly, we should be able to get this working.

wim leers’s picture

Issue tags: +D8 cacheability

Indeed, #2273277: Figure out a solution for the problematic interaction between the render system and the theme system when using #pre_render landed, which makes it possible to push this one forward again. I'll provide reviews!

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new19.83 KB

Attached a straight reroll of #18

Also, I wanted to mention some considerations now that we are moving twig files into classy in the Banana Phase 2:

New twig file:

  • core/modules/system/templates/block--system-page-messages-block.html.twig - No CSS classes in here.

Core twig files modified:

  • core/modules/system/templates/install-page.html.twig
  • core/modules/system/templates/maintenance-page.html.twig
  • core/modules/system/templates/page.html.twig

I put this here so that we can take a look down the road.

joelpittet’s picture

Status: Needs review » Needs work
+++ b/core/includes/theme.inc
@@ -1800,6 +1800,12 @@ function drupal_common_theme() {
+    // @TODO change this to status_messages once the messages are gone from
+    // template_preprocess_page
+    'status_messages_block' => array(
+      'variables' => array('status_headings' => array(), 'message_list' => NULL),
+      'template' => 'status-messages',
+    ),

This @todo needs to be dealt with here. Any suggestions to make this work/go away?

The last submitted patch, 25: 2289917-25-convert-messages-element.patch, failed testing.

wim leers’s picture

#26: just remove it from template_preprocess_page() and page.html.twig?

manuel garcia’s picture

Status: Needs work » Needs review
Issue tags: +Classy
StatusFileSize
new20.85 KB
new5.79 KB

OK, here is some work on this:

Fixed these two errors that were coming up on site installation:

  • Error: Class 'Drupal\block\BlockBase' not found in /var/www/drupal8/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php, line 23
  • PHP Fatal error: Declaration of Drupal\system\Plugin\Block\SystemPageMessagesBlock::buildConfigurationForm() must be compatible with Drupal\Core\Plugin\PluginFormInterface::buildConfigurationForm(array $form, Drupal\Core\Form\FormStateInterface $form_state) in /var/www/drupal8/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php on line 23

And fixed also this one when you tried visiting the site:

  • Fatal error: Call to undefined method Drupal\Core\Theme\ThemeNegotiator::getActiveTheme() in /var/www/drupal8/core/modules/block/block.module on line 274

I then tried to work on that @todo, but messages are not showing up apparently... could use some guidance!

Status: Needs review » Needs work

The last submitted patch, 29: 2289917-29-convert-messages-element.patch, failed testing.

wim leers’s picture

Assigned: Unassigned » wim leers

I'm making the changes necessary to get messages to work again, to unblock you. Will post patch tomorrow morning CET.

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Needs review
StatusFileSize
new23.55 KB
new5.78 KB
new24.49 KB
new4.81 KB
new8.12 KB

Fixed the patch, now messages show up, except that show_messages (just grep for that and you'll about 1.5 dozen matches) is not yet taken into account, that's an important thing to fix still.
That's patch 31.


But there's more :) This should either:
  1. NOT use #post_render_cache and keep \Drupal\system\Plugin\Block\SystemPageMessagesBlock::isCacheable() returning FALSE
  2. OR keep using #post_render_cache and make \Drupal\system\Plugin\Block\SystemPageMessagesBlock::isCacheable() return TRUE

Right now, we're not caching it, and generating a render cache placeholder every request. That's pointless. #post_render_cache already ensures that something that is not cacheable becomes cacheable, by only storing a placeholder. Which makes the block perfectly cacheable.

But…actually, only option 2 allows for the messages block being placed multiple times. So we should go with option 2.

And when doing that, we can also optimize things a bit more: instead of rendering the messages N times (for N messages blocks), having N #post_render_cache callbacks executed, and having to replace the placeholder in the HTML N times… we can reduce all those Ns to just 1. After all, each messages block must contain exactly the same messages. So by ensuring that we generate exactly the same placeholder, we can enforce that more optimal behavior :)

The last submitted patch, 32: 2289917-31-convert-messages-element.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 32: 2289917-32-convert-messages-element.patch, failed testing.

wim leers’s picture

No actual changes in the number of test failures/exceptions, because those are not caused by messages not appearing, but by other things being broken :)

manuel garcia’s picture

Looking at the failing tests here... I see this warning all over the place on the failing tests:
mb_strtolower() expects parameter 1 to be string, object given

Line 299 on file Unicode.php function Drupal\Component\Utility\Unicode::strtolower()

Any clue what it is?

wim leers’s picture

It's receiving an object instead of a string. Just add a

if (!is_string($parameter)) {
  debug(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10));
}

to figure out which calling code is responsible.

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new22.73 KB
new474 bytes

This should fix some of the failing tests

Status: Needs review » Needs work

The last submitted patch, 38: convert_messages_page-2289917-38.patch, failed testing.

joelpittet’s picture

Thanks for picking this up @Wim Leers and nice catch @lauriii.

Few little items when reviewing the code for this:

  1. +++ b/core/modules/system/templates/install-page.html.twig
    @@ -30,7 +30,10 @@
    -      {{ messages }}
    ...
    +      {% if messages %}
    +        {{ messages }}
    +      {% endif %}
    

    This is not necessary at all, won't change anything but not needed because it will just print nothing if empty. If you need to print messages just leave it in there, or move it if need be.

  2. +++ b/core/modules/system/templates/maintenance-page.html.twig
    @@ -41,7 +41,11 @@
    -    {{ messages }}
    ...
    +    {% if messages %}
    +      {{ messages }}
    +    {% endif %}
    

    Same here.

  3. +++ b/core/themes/bartik/templates/status-messages.html.twig
    @@ -0,0 +1,58 @@
    +{% set has_messages = 0 %}
    +{% for type, messages in message_list %}
    +  {% if messages|length > 0 %}
    +    {% set has_messages = 1 %}
    +  {% endif %}
    +{% endfor %}
    

    This variable prep logic should be in preprocess and send the variable to the template.

  4. +++ b/core/themes/bartik/templates/status-messages.html.twig
    @@ -0,0 +1,58 @@
    +{% if has_messages %}
    +<div id="messages"><div class="section clearfix">
    +{% for type, messages in message_list %}
    

    Our indentation coding standards issues here. Each div should be nested in it's own line and we are indenting the after the if to be inline with twig coding standards.

  5. +++ b/core/themes/bartik/templates/status-messages.html.twig
    @@ -0,0 +1,58 @@
    +        {{ messages.0 }}
    +      {% endif %}
    +    {% if type == 'error' %}
    +      </div>
    

    Indent is weird here. One needs to go forward or back.

  6. +++ b/core/themes/bartik/templates/status-messages.html.twig
    @@ -0,0 +1,58 @@
    +</div></div> <!-- /.section, /#messages -->
    

    No need for the inline comment.

Those likely won't fix the problem but may help spot something that could inch it forward some more;)

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new23.34 KB
new522 bytes

This should fix some more tests.

Status: Needs review » Needs work

The last submitted patch, 41: convert_messages_page-2289917-40.patch, failed testing.

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new3.5 KB
new23.72 KB

Thanks @joelpittet for the review! I fixed points from #40.

lauriii’s picture

StatusFileSize
new23.11 KB
new789 bytes

Lets try this to fix most of the tests..

The last submitted patch, 43: convert_messages_page-2289917-42.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 44: convert_messages_page-2289917-44.patch, failed testing.

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new23.04 KB
new1.13 KB

Hmm lets see now

joelpittet’s picture

Holy cross post batman, that's twice crossposted with testbot and laurriii...

Thanks a bunch @lauriii for tracking down those bugs again and fixing the nitpicks, here's a couple more and a question on that preprocess/template.

  1. +++ b/core/includes/theme.inc
    @@ -1789,7 +1763,8 @@ function drupal_common_theme() {
    +      'variables' => array('status_headings' => array(), 'message_list' => NULL),
    

    Short array syntax.

  2. +++ b/core/themes/bartik/bartik.theme
    @@ -110,6 +110,13 @@ function bartik_preprocess_menu(&$variables) {
    +function bartik_preprocess_status_messages(&$variables) {
    +  $variables['has_messages'] = !empty($variables['message_list']);
    

    Weird, I wonder why bartik only getting this? Shouldn't that be something core needs? And before, it was checking for the key messages is empty, could you do the equivalent in PHP?

  3. +++ b/core/themes/seven/templates/install-page.html.twig
    @@ -27,7 +27,10 @@
    +    {% if messages %}
    +      {{ messages }}
    +    {% endif %}
    

    One more of these unnecessary if statements.

Status: Needs review » Needs work

The last submitted patch, 47: convert_messages_page-2289917-47.patch, failed testing.

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new30.85 KB
new9.66 KB

Lets see if its going to right direction

I also removed messages variable from templates because the variable is not set anymore so I couldn't figure out why it should be still there

Status: Needs review » Needs work

The last submitted patch, 50: convert_messages_page-2289917-50.patch, failed testing.

Scionar’s picture

Assigned: Unassigned » Scionar
Scionar’s picture

Assigned: Scionar » Unassigned
StatusFileSize
new24.47 KB

Added 'block' into modules array and system_page_messages_block added. Not enough time to do more. At Drupal-sprint FI.

Scionar’s picture

StatusFileSize
new46.34 KB

Added interdiff.

manuel garcia’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 53: convert_messages_page-2289917-53.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new32.99 KB

Ignoring #53/#54 because it's several kilobytes less in patch size and the interdiff is suspiciously large.

Straight reroll of #50 (had to fix 2 conflicts), then pushing this forward a bit.

(No worries, Scionar, we've all been there. It takes a while to get that patch stuff going well :))

wim leers’s picture

StatusFileSize
new31.79 KB
new2.49 KB

Review. Minor reroll attached, which fixes whitespace nits + point 3 below.

  1. +++ b/core/modules/block/block.module
    @@ -258,6 +258,37 @@ function template_preprocess_block(&$variables) {
    +function block_preprocess_page(&$variables) {
    

    I'd like us to get rid of this, in favor of the approach in #507488-137: Convert page elements (local tasks, actions) into blocks, if possible. That'd be consistent with these other "essential page elements".

  2. +++ b/core/modules/block/src/BlockListBuilder.php
    @@ -296,6 +296,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    +    // Do not allow disabling the status messages block when it is present.
    +    if (isset($form['blocks']['system_page_messages']['region'])) {
    +      $form['blocks']['system_page_messages']['region']['#required'] = TRUE;
    +    }
    

    This doesn't actually work. E.g. for Bartik, this block is called bartik_messages.

    It also seems unnecessary, because we don't do this for the main content block either.

  3. +++ b/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php
    @@ -0,0 +1,129 @@
    +  protected $configFactory;
    

    This is never used, so we can significantly simplify SystemPageMessagesBlock. Done.

  4. +++ b/core/themes/bartik/bartik.theme
    @@ -110,6 +110,13 @@ function bartik_preprocess_menu(&$variables) {
     /**
    + * Implements hook_preprocess_HOOK() for status-messages.html.twig.
    + */
    +function bartik_preprocess_status_messages(&$variables) {
    +  $variables['has_messages'] = !empty($variables['message_list']);
    +}
    

    Don't we define logic like this in the Twig templates themselves nowadays?

  5. +++ b/core/themes/bartik/templates/maintenance-page.html.twig
    @@ -39,13 +39,7 @@
    -            {% if messages %}
    -              <div id="messages">
    -                <div class="section clearfix">
    -                  {{ messages }}
    -                </div>
    -              </div>
    -            {% endif %}
    +            {{ page.messages }}
    

    I don't think the maintenance page (or install page) can ever use blocks. They have regions, yes, but not blocks.
    So we'll need to make sure we fill the messages region with something even when the block module is disabled. Which is why I referred to that other issue earlier.

The last submitted patch, 57: convert_messages_page-2289917-57.patch, failed testing.

wim leers’s picture

StatusFileSize
new33.51 KB
new3.01 KB
  1. The included block schema was invalid. Easy fix; removes a few test failures.
  2. The cache tags for the messages block is now present on pages, updated PageCacheTagsIntegrationTest

The last submitted patch, 58: convert_messages_page-2289917-58.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 60: convert_messages_page-2289917-60.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new38.35 KB
new6.63 KB

Fixed a few tests.

Funny one: BlockTestBase::setUp() was creating a messages block, but later during that function, all existing blocks are deleted… :) So it couldn't possibly work. This should help reduce the number of test failures by another bit.

Fixing everything like this feels wrong though. See #58.1 & #58.5. Doing that now.]

EDIT: oops, debug additions while gearing up for that next step made it into this patch + interdiff. This will fail majestically.

Status: Needs review » Needs work

The last submitted patch, 63: convert_messages_page-2289917-63.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new36.46 KB
new11.57 KB

Reverted all changes in #63, except those in BlockTest(Base). The SimplePageVariant (used when block module is not active) now also renders messages. This is what is causing the majority of the test failures, and should thus help significantly in bringing this closer to zero test failures.

Note that we want to remove the drupalPlaceBlock() calls added in previous patches whenever we also had to enable the block module.

That leaves only one important matter to decide: when block module is enabled, do we require a messages block to be placed, or do we want to automatically provide a fallback? If we don't automatically provide a fallback (we currently don't, yet), then it's easy for a site builder to end up with a site that never shows messages (i.e. when the messages block is removed).

Status: Needs review » Needs work

The last submitted patch, 65: convert_messages_page-2289917-65.patch, failed testing.

wim leers’s picture

593 fails. Much better.

Most of the remaining ones are probably for the case where block module is being used, but the messages block is not being placed yet.

Can't we make WebTestBase::setUp() check which modules are being installed, and if the block module is also being installed, then place the messages block automatically?

Jeff Burnz’s picture

do we require a messages block to be placed, or do we want to automatically provide a fallback?

Just thinking about that, won't we need a fallback to warn about placing a block? Could we possibly render messages via one of the core regions, like page.top if no block is placed, but provide a warning that the block should be placed?

fabianx’s picture

I think we should do it the same way as for MainContentInterface and PageTitleInterface have a PageMessagesInterface.

That is then:

a) Consistent with what we have elsewhere
b) Provides the fallback
c) Still makes it possible to configure the block

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new39.97 KB
new4.33 KB

Agreed.

Done. This should be green or very close to green.

Next reroll: removing all those drupalPlaceBlock() additions.

wim leers’s picture

Issue tags: -Needs tests
StatusFileSize
new28.49 KB
new11.58 KB

Now we can make the patch significantly smaller.

I think the thousands of test failures above show we have sufficient test coverage.

wim leers’s picture

We will still have the failures caused by shortcut module's shortcut_preprocess_page().
LOL, no, that's in #507488: Convert page elements (local tasks, actions) into blocks. My bad.

The last submitted patch, 70: convert_messages_page-2289917-70.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 71: convert_messages_page-2289917-71.patch, failed testing.

wim leers’s picture

Unfortunately still 30 fails (but that's >500 less than before), but fortunately #71 has exactly the same fails with a 28% smaller patch :) Hunting down those last 30.

fabianx’s picture

  1. +++ b/core/lib/Drupal/Core/Render/Element/StatusMessages.php
    @@ -0,0 +1,122 @@
    +    // Replace the placeholder.
    +    $callback = get_class() . '::renderMessages';
    +    $placeholder = $renderer->generateCachePlaceholder($callback, $context);
    +    $element['#markup'] = str_replace($placeholder, $markup, $element['#markup']);
    +    $element = $renderer->mergeBubbleableMetadata($element, $messages);
    

    We really really need to make this API easier to use. It is way too low-level.

    Not the fault of this issue though.

  2. +++ b/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php
    @@ -0,0 +1,69 @@
    +    $form['cache']['max_age']['#value'] = -1;
    +    $form['cache']['max_age']['#disabled'] = TRUE;
    

    Should use Cache::PERMANENT to make this explicit.

Except for the usage of hard-coded -1 and the failing tests this would be RTBC for me.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new29.07 KB
new13.97 KB

#76.1: indeed, out of scope here.

#76.2: fixed, great catch, I missed that :)


This reroll should fix the majority (if not all) of the remaining test failures. Summary of changes:

  1. #theme => messages -> #type => messages
  2. Messages are rendered via #post_render_cache and hence drupal_render_root() must be used. As should have been the case for all these AJAX command callbacks already anyway.

Status: Needs review » Needs work

The last submitted patch, 77: convert_messages_page-2289917-77.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new41.25 KB

Interdiff was right, patch was wrong. Rerolled.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs change record updates

Needs a change record OR change record updates for the #theme => #type change and integration.

wim leers’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 79: convert_messages_page-2289917-79.patch, failed testing.

davidhernandez’s picture

Shouldn't there be a change record about the actual change here? Removing the availability of 'messages' for page templates and converting it into a block.

wim leers’s picture

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new45.68 KB
new5.14 KB

This fixes the 3 failures in BlockPageVariantTest and expands the test coverage.

Status: Needs review » Needs work

The last submitted patch, 85: convert_messages_page-2289917-85.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new49.71 KB
new4.86 KB

Most of the remaining failures were due to #show_messages on the BareHtmlPageRenderer.

But the failure in SystemAuthorizeTest I spent hours debugging, thanks to this gem introduced in one of the patches above:

diff --git a/core/themes/seven/templates/maintenance-page.html.twig b/core/themes/seven/templates/maintenance-page.html.twig
index f2bc53b..1e6acef 100644
--- a/core/themes/seven/templates/maintenance-page.html.twig
+++ b/core/themes/seven/templates/maintenance-page.html.twig
@@ -27,8 +27,7 @@
     {% if title %}
       <h1>{{ title }}</h1>
     {% endif %}
-    {{ messages }}
-    {{ page.content }}
+    {{ page.messages }}
   </main>
 
   {% if page.page_bottom %}

… note how page.content is removed. ARGH!!!!!!

This still won't be green, but will be very close.

Status: Needs review » Needs work

The last submitted patch, 87: convert_messages_page-2289917-87.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new50.67 KB
new1.83 KB

A bunch of installer-related test failures appeared in #87 because the installer was now actually trying to show messages again, but doing so failed because the hash salt isn't set yet during the installation.

This will hopefully be green.

fabianx’s picture

+++ b/core/lib/Drupal/Core/Render/Element/StatusMessages.php
@@ -55,8 +55,16 @@ public static function generatePlaceholder(array $element) {
+    catch (\RuntimeException $e) {
+      // Status messages are also shown during the installer, at which time no
+      // hash salt is defined yet.
+      $hash_salt = Crypt::randomBytes(8);
+    }

Ugh, that is unfortunate.

Not the fault of this patch, though.

Interdiff looks good! Lets see once we are green :).

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

Has tests, has change record updates, the type messages here is fine and makes sense as you usually just place the block anyway.

Therefore:

RTBC! Great work!

wim leers’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new49.97 KB
new8.59 KB

And a bit of clean-up.

Most notable changes pointed out:

  1. +++ b/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php
    @@ -0,0 +1,70 @@
    + * Contains \Drupal\system\Plugin\Block\SystemPageMessagesBlock.
    ...
    + * Provides a block to display the page messages.
    ...
    + *   admin_label = @Translation("Page messages")
    ...
    +class SystemPageMessagesBlock extends BlockBase implements MessagesBlockPluginInterface {
    

    IMO the "page" part here should be omitted; this is just about "messages", period. There's nothing page-specific about them.

    The only reason the "page" prefix is here, is because it used to be in the page template.

  2. +++ b/core/themes/bartik/bartik.theme
    @@ -110,6 +110,13 @@ function bartik_preprocess_menu(&$variables) {
    +function bartik_preprocess_status_messages(&$variables) {
    +  $variables['has_messages'] = !empty($variables['message_list']);
    +}
    

    Why not just use

    {% if message_list is not empty %}
    

    in Twig instead of creating this variable and then doing

    {% if has_messages %}
    

    ?

    A preprocess function is pointless here.

  3. +++ b/core/themes/bartik/templates/status-messages.html.twig
    @@ -0,0 +1,53 @@
    +      {% for type, messages in message_list %}
    +        <div class="messages messages--{{ type }}" role="contentinfo" aria-label="{{ status_headings[type] }}">
    +          {% if type == 'error' %}
    +            <div role="alert">
    +          {% endif %}
    +            {% if status_headings[type] %}
    +              <h2 class="visually-hidden">{{ status_headings[type] }}</h2>
    +            {% endif %}
    +            {% if messages|length > 1 %}
    +              <ul class="messages__list">
    +                {% for message in messages %}
    +                  <li class="messages__item">{{ message }}</li>
    +                {% endfor %}
    +              </ul>
    +            {% else %}
    +              {{ messages.0 }}
    +            {% endif %}
    +          {% if type == 'error' %}
    +            </div>
    +          {% endif %}
    +        </div>
    +      {% endfor %}
    

    All this is copy/pasted directly from classy's template. So why not just inherit that? All Bartik wants is that wrapper.

    Another reason: Classy's template has been improved since, and this template was not updated accordingly. By using inheritance, we prevent the need to keep them in sync manually.

wim leers’s picture

StatusFileSize
new50 KB
new675 bytes

And a tiny additional bit for SimplePageVariant, to ensure messages are shown above.

The last submitted patch, 92: convert_messages_page-2289917-91.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 93: convert_messages_page-2289917-93.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new49.99 KB
new1.19 KB
fabianx’s picture

I would love to RTBC this, but looking closer again and re-reviewing all code, there is two things:

a) 'display' needs to be brought back as parameter, else this is an API change of sorts. (can just put in context and pass through to #post_render_cache, so should be fine - ).

+ $plugin_id => $context,

but this will need to change to a key thats dependent on what is displayed else there will be only one item in post_render_cache as far as I have understood post_render_cache. (Might be wrong, but I know I had trouble with that notion when working my RenderCachePlaceholder class).

b) Template changes should quickly be verified by Cottser and the bartik changes by emmamaria. While the markup keeps the same the location changes and I know themers might care about this.

c) It might be nice (though probably - maybe not - out of scope) to add a configurable parameter to the block to select 'Status', Errors, etc.

That would actually be pretty cool to be able to place multiple blocks for that in different regions and probably a reason why a) display existed in the first place in the API.

And might be a good test case for a).

wim leers’s picture

StatusFileSize
new50.22 KB
new1.77 KB

a)

Great catch.

+++ b/core/includes/theme.inc
@@ -523,25 +523,6 @@ function template_preprocess_datetime_wrapper(&$variables) {
- * @param array $variables
- *   An associative array containing:
- *   - display: (optional) May have a value of 'status' or 'error' when only
- *     displaying messages of that specific type.
- */
-function template_preprocess_status_messages(&$variables) {
-  $variables['message_list'] = drupal_get_messages($variables['display']);

So it's about bringing this back. It's not used by anything in core, but removing it would be an API change.

Done!


b) Agreed. Markup is identical before & after, but still, we want this to be verified.


c) That's indeed out of scope. Also a bad idea UX-wise — that should be available only to developers & themers. If we give users that choice, it's too easy to end up with a site that is broken. AFAIK it was always intended for developers & themers only. That's why it's only in the API and nowhere to be seen in the UI (in D8 nor D7/6/5).

star-szr’s picture

Status: Needs review » Needs work

As requested here is a general review of the Twig/template action. Only minor points.

  1. +++ b/core/includes/theme.inc
    @@ -1789,7 +1762,8 @@ function drupal_common_theme() {
         'status_messages' => array(
    -      'variables' => array('display' => NULL),
    +      'variables' => ['status_headings' => [], 'message_list' => NULL],
    +      'template' => 'status-messages',
         ),
    
    +++ b/core/modules/system/system.module
    @@ -168,6 +168,10 @@ function system_theme() {
    +    'block__system_messages_block' => array(
    +      'base hook' => 'block',
    +      'template' => 'block--system-messages-block',
    +    ),
    

    These 'template' lines should (hopefully) no longer be needed :D https://www.drupal.org/node/2231673

  2. +++ b/core/themes/bartik/templates/status-messages.html.twig
    @@ -0,0 +1,35 @@
    +{% extends "@classy/system/status-messages.html.twig" %}
    ...
    +{% block messages %}
    ...
    +{% endblock messages %}
    
    +++ b/core/themes/classy/templates/system/status-messages.html.twig
    @@ -25,6 +25,7 @@
    +{% block messages %}
    
    @@ -55,3 +56,4 @@
    +{% endblock messages %}
    

    General question: why extend Classy's status messages template when everything is being replaced?

  3. +++ b/core/themes/bartik/templates/status-messages.html.twig
    @@ -0,0 +1,35 @@
    + * @ingroup themeable
    

    Anything but the default template from a module should not have @ingroup themeable - https://www.drupal.org/node/1823416#docblock

    Unfortunately I just found that all or nearly all Classy templates have this same issue :/

  4. +++ b/core/themes/classy/templates/system/page.html.twig
    @@ -31,7 +31,6 @@
    - * - messages: Status and error messages. Should be displayed prominently.
    

    In Classy's page.html.twig the 'messages' variable documentation is removed but page.messages is not added to the regions documentation like in the other templates.

Edited to add better context and expand one of the code snippets.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new50.45 KB
new2.32 KB
  1. Nice, done! :)
  2. Bartik merely wants to add an additional wrapper around the markup that Classy generates. i.e.:
    1. +++ b/core/themes/bartik/templates/page.html.twig
      @@ -109,11 +109,7 @@
      -    {% if messages %}
      -      <div id="messages">
      -        <div class="section clearfix">{{ messages }}</div>
      -      </div>
      -    {% endif %}
      

      We used to have this…

    2. +++ b/core/themes/bartik/templates/status-messages.html.twig
      @@ -0,0 +1,35 @@
      +{% block messages %}
      +  {% if message_list is not empty %}
      +    <div id="messages">
      +      <div class="section clearfix">
      +        {{ parent() }}
      +      </div>
      +    </div>
      +  {% endif %}
      +{% endblock messages %}
      

      … and now it lives here.

  3. That makes sense, since this template was originally a copy of Classy. Now removed.
  4. Nice catch, fixed.
star-szr’s picture

@Wim Leers - I totally missed the use of parent() - nicely done! I would be so happy to see that actually being used in core, or at least a core theme :)

wim leers’s picture

#101: Glad you like it :) core/themes/bartik/templates/block--search-form-block.html.twig already uses it though, so this won't be the first :)

kim.pepper’s picture

Did a quick review, and found one small nitpick:

  1. +++ b/core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php
    @@ -49,6 +49,12 @@ public function renderBarePage(array $content, $title, $page_theme_property, arr
    +    // @todo In Drupal 9, add a $show_messages function parameter.
    

    Can we please have an issue for this?

rainbowarray’s picture

So happy to see this so close to getting in. Big thanks to all who worked to make that happen!

wim leers’s picture

#103: AFAIK we don't file issues for D9 @todos? At least we don't for @deprecated stuff, which implies an @todo also. It's just a note when revising this in the future; hopefully the entire "bare HTML page renderer" concept can go away in D9. Since it's an API we'd rather get rid of, it feels unnecessary to file an issue for it.

emma.maria’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
emma.maria’s picture

Assigned: Unassigned » emma.maria
emma.maria’s picture

Assigned: emma.maria » Unassigned
Status: Needs work » Needs review
StatusFileSize
new47.67 KB

Rerolled, I will now take a look at Bartik with this patch.

Status: Needs review » Needs work

The last submitted patch, 108: convert_messages_page-2289917-108.patch, failed testing.

fabianx’s picture

I think this line will be the culprit:

+{% extends "@classy/system/status-messages.html.twig" %}

it should be:

{% extends "status-messages.html.twig" %} per https://www.drupal.org/node/2381103

so that it automatically extends from bartik ...

But hmm, that is the same file, so won't work, so need to specify the right path where system-messages.html.twig now lives after classy move.

--

Do we need a:

+{% extends "base-theme:status-messages.html.twig" %}

or such directive in a follow-up?

davidhernandez’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new47.67 KB
new426 bytes
davidhernandez’s picture

The folder moved because of the Classy reorganization. This template file is extending a template with the same name, so the namespace and path to file has to be declared explicitly.

emma.maria’s picture

Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new23.12 KB
new19.98 KB
new28.81 KB
new17.38 KB
new28.15 KB
new29.27 KB
new34.91 KB
new32.96 KB

From a visual review of the patch, I noticed the messages block are in quite different places to where they originally were.

Admin pages

Messages printing at bottom of admin pages - in Seven and Bartik - this is a bug.

Seven - before patch

Seven - after patch

Bartik - before patch

Bartik - after patch

Frontend

Messages have moved from being just above content to below the title - which looks really different in Bartik

Bartik - before patch

Bartik - after patch

Classy - before patch

Classy - after patch

star-szr’s picture

Re #110 don't want to derail but #2387069: {% extends "foo.html.twig" %} in Twig templates does not respect theme inheritance would be a good place to potentially add that follow-up mentioned as a related issue ;)

Jeff Burnz’s picture

#113 is that on a new install, they look like they're not in the right regions?

emma.maria’s picture

@Jeff Burnz I thought it was a fresh install, on reflection after that review at midnight I may try again.

emma.maria’s picture

Issue summary: View changes

No I was right about the admin messages! On a fresh install the messages still print underneath the admin section as per #113.
 

%nbsp;
I dropped the database, cleared files and reinstalled Drupal with the patch applied.

Frontend messages work correctly, apologies for reporting them.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new50.86 KB
new713 bytes

Admin pages:

  • Seven didn't have a "Messages" block yet, so it was using the fallback.
  • The Bartik problem you showed must be due to something being changed in the block layout because that cannot be reproduced with a fresh install.

UPDATE: emmamaria has now indicated there's indeed no problem on the frontend.

Frontend:

  • Again, the Bartik problem you showed must be due to something being changed in the block layout because that cannot be reproduced with a fresh install.
  • Classy isn't installed by default so what you're seeing here is the fallback behavior. This is expected. By placing a "Messages" block, the messages would appear in the original location again. Note that once #507488: Convert page elements (local tasks, actions) into blocks is solved, the "before" would again become reality, but because the title and local tasks are currently hardcoded in the page template, there is no way to make the default behavior match the "before" picture right now. (Unless we make SimplePageVariant and BlockPageVariant render the fallback messages in the messages region, but that should be avoided, since not every theme will have a messages region; we only require a content region.

Status: Needs review » Needs work

The last submitted patch, 119: convert_messages_page-2289917-116.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new48.25 KB

The interdiff for #119 was correct, the patch was flawed (some other file snuck in).

fabianx’s picture

> Seven didn't have a "Messages" block yet, so it was using the fallback.

But shouldn't that fallback end up in page.messages as well and hence be at the right position?

wim leers’s picture

#122: No, see the deleted last bullet in #119.

fabianx’s picture

Thanks for the explanation! :)

emma.maria’s picture

Status: Needs review » Needs work

The patch is still not happy.
Tried applying and get this mid applying...

Checking patch core/modules/system/src/Plugin/Block/SystemMessagesBlock.php...
Checking patch core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php...
error: while searching for:
      'config:block.block.bartik_powered',
      'config:block.block.bartik_main_menu',
      'config:block.block.bartik_account_menu',
      'block_plugin:system_breadcrumb_block',
      'block_plugin:system_main_block',
      'block_plugin:system_menu_block__account',

error: patch failed: core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php:94
error: core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php: patch does not apply
Checking patch core/modules/system/src/Tests/Theme/MessageTest.php...
wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new50.35 KB
jibran’s picture

Issue summary is not up to date with current patch approach and we do need beta evaluation. We also need a change record for #type => 'status_messages'

  1. +++ b/core/lib/Drupal/Core/Block/MessagesBlockPluginInterface.php
    @@ -0,0 +1,19 @@
    +interface MessagesBlockPluginInterface extends BlockPluginInterface { }
    

    I don't see any reason for adding this.
    Oh ok I see it's used in BlockPageVariant now $messages_block_displayed = TRUE; can we add docs related to that here some @see and explanation would be great.

  2. +++ b/core/lib/Drupal/Core/Render/Element/StatusMessages.php
    @@ -0,0 +1,135 @@
    +class StatusMessages extends RenderElement {
    

    Can we add a @code block in the docs with some examples here?

  3. +++ b/core/lib/Drupal/Core/Render/Element/StatusMessages.php
    @@ -0,0 +1,135 @@
    +      '#message_list' => drupal_get_messages($context['display']),
    

    Can we add a @todo here #2278383: Create an injectible service for drupal_set_message()?

  4. +++ b/core/modules/file/src/Controller/FileWidgetAjaxController.php
    @@ -38,8 +38,8 @@ public function upload(Request $request) {
    +      return $response->addCommand(new ReplaceCommand(NULL, drupal_render_root($status_messages)));
    
    @@ -53,8 +53,8 @@ public function upload(Request $request) {
    +      return $response->addCommand(new ReplaceCommand(NULL, drupal_render_root($status_messages)));
    
    @@ -76,9 +76,9 @@ public function upload(Request $request) {
    +    $form['#prefix'] .= drupal_render_root($status_messages);
    +    $output = drupal_render_root($form);
    
    +++ b/core/modules/quickedit/src/QuickEditController.php
    @@ -204,7 +204,7 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
    +      $output = drupal_render_root($form);
    
    @@ -214,9 +214,9 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
    +        $response->addCommand(new FieldFormValidationErrorsCommand(drupal_render_root($status_messages)));
    
    +++ b/core/modules/system/form.api.php
    @@ -153,8 +153,8 @@ function callback_batch_finished($success, $results, $operations) {
    +  $command = new \Drupal\Core\Ajax\PrependCommand('#block-system-main .content', drupal_render_root($status_messages));
    
    +++ b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
    @@ -203,7 +203,7 @@ protected function ajaxFormWrapper($form_class, FormStateInterface &$form_state)
    +    $output = drupal_render_root($form);
    
    @@ -220,8 +220,8 @@ protected function ajaxFormWrapper($form_class, FormStateInterface &$form_state)
    +      if ($messages = drupal_render_root($status_messages)) {
    

    Let's not use deprecated functions.

fabianx’s picture

Issue tags: -Needs change record

https://www.drupal.org/node/2446615 is the CR, leaving the rest to Wim.

emma.maria’s picture

Status: Needs review » Needs work
StatusFileSize
new56.34 KB
new200.2 KB

Patch applies cleanly.

Messages print in the same places as core right now with the patch applied - admin and frontend, which is great.

Review of the Bartik theme.

I have a few nitpicks

  1. The location of the new messages region on the block layout page.
    In theory it should be below the menus and above Featured top, this is where it prints on the frontend.
     
  2.  

  3. I really do not like an empty region
    printing for messages when there are no messages being currently displayed.
     
    <div class="region region-messages"></div>
     
    This can cause visual problems for Bartik. For example if messages are put in the Featured Top region, the region has a background colour and padding. It will print those styles no matter if there are messages or not. As we are making messages a block and flexible in placement, we should make sure the block doesn't break anything visually. See below...
     
    Only local images are allowed.
     
    Can this be changed?

     

  4. One last thing, does the region have to be called Messages? We shouldn't create and name regions based on the content we happen to be putting in them at the time. I know Bartik currently does that a lot but that is for purposeful visual design. This is a bit different.
wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new55.59 KB
new12.52 KB

#127:

As FabianX said, the CR already existed.

  1. Done.
  2. We don't do this for any other render element. So I don't see why we'd do it for this one.
  3. There wasn't a @todo there prior… but, sure, added.
  4. The patch is already 50 KB. Using the non-deprecated functions implies adding injection as well. I wanted to minimize the number of changes, to stay as much on-topic as possible. But, since you asked: done. (Injected everywhere except for ViewsFormBase, because injecting it there causes a huge chain of changes.)

#129:

  1. Moved.
  2. That's a problem that isn't specific to this issue, nor introduced by this issue. Place the tools menu block in e.g. the right sidebar or the featured top region, visit it as the anonymous user (which cannot access any of the menu links, hence no menu block is rendered), and witness the exact same problem. That's up to #953034: [meta] Themes improperly check renderable arrays when determining visibility to solve.
  3. IMO it doesn't, but a long time ago, it was decided to go about converting page elements into blocks this way. We did the same for primary & secondary menus, breadcrumbs, etc. The idea is to revise the regions once all conversions are done. This is the one but last conversion — #507488: Convert page elements (local tasks, actions) into blocks will be the last!
emma.maria’s picture

Thanks @Wim Leers for explaining everything to me. I came across those things when testing and was not aware of all of the history and other issues.

I agree with the patch changes and comments in #130. Bartik is signed off for this issue.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC - if tests pass.

jibran’s picture

WoW @Wim Leers you are awesome. This is ready just need beta evaluation and a little explanation for core dev related to current approach.
I don't this but do we have to update some doc files in a follow up or some meta issue to update http://api.drupal.org/api/drupal/developer%21topics%21forms_api_referenc...?

wim leers’s picture

Issue summary: View changes

Beta evaluation added.

RE: FAPI reference: this isn't FAPI :) It's a @RenderElement, not a @FormElement.

wim leers’s picture

Issue summary: View changes

IS updated to explain the approach in the patch better.

star-szr’s picture

Looks great, thanks all especially @Wim Leers for driving this home!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed d89c1f7 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

diff --git a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php
index 8f20101..798805e 100644
--- a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php
+++ b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php
@@ -157,7 +157,7 @@ public function build() {
       $build['content']['system_main'] = $this->mainContent;
     }
 
-    // Analogously for messages.
+    // If no block displays status messages, still render them.
     if (!$messages_block_displayed) {
       $build['content']['messages'] = [
         '#weight' => -1000,

Made a code comment a bit more explicit on commit.

  • alexpott committed d89c1f7 on
    Issue #2289917 by Wim Leers, mdrummond, lauriii, Manuel Garcia, emma....

Status: Fixed » Needs work

The last submitted patch, 130: convert_messages_page-2289917-130.patch, failed testing.

wim leers’s picture

Status: Needs work » Fixed

Testbot was probably testing this patch again immediately after it got committed.

Now let's continue over at #507488: Convert page elements (local tasks, actions) into blocks, which is now unblocked!

Jeff Burnz’s picture

Hooray! Thank-you so much Wim, and everyone else who worked hard on this issue, massively appreciated.

wim leers’s picture

star-szr’s picture

8 days later but I created the issue for #99.3 :) #2452361: Remove "@ingroup themeable" from all Classy templates

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.