... not sure if it coheres with this issue #1049648: StatusMessages::renderMessages() is destructive in core, but it seems that some messages didn't show up when print render($messages); is not in page.tpl.php and the delta messages block is taking over. I like the idea of rather having them as block available for user roles and easy block handling. But as long as it isn't sure that it 99,9% works, I think it could be too risky to have some message warnings not popping up with messages block playing the ball ...

to reproduce: Drupal 7.10 with latest devel --dev and delta --dev and ... /* print render($messages); */ ... turned off (or commented out) in page.tpl.php, and the messages block should be moved to a sidebar region or anywhere else, of course. Now try to activate "print page array" in devel options. You will see that it prints regulary on seven admin theme or any other theme with print render($messages); , but not in the one, where it is commented out in the page.tpl.php and where the messages block is activated.

I took a look into the delta_blocks.module code, but there seems to be nothing fishy ... (maybe theme('status_messages') needs to be called earlier)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dqd’s picture

Issue tags: +block, +core, +messages, +status_messages

some message popup modules have the same problem, not sure if it all coheres with the core issue ...

dqd’s picture

Issue summary: View changes

forgot to describe further devel option to reproduce the scenario

dqd’s picture

Issue summary: View changes

typo

dqd’s picture

Issue summary: View changes

typo again ... arg

dqd’s picture

Title: theme('status_messages') seems not to filled in some scenarios » theme('status_messages') seems to leave out some scenarios
mjpa’s picture

Status: Active » Needs review
FileSize
1.9 KB

This basically happens because the Messages block will only see the messages that have been set before it's block's content is fetched by Drupal. Any messages that are set by blocks that are fetched after the Messages block as well as messages set in hooks that are called after the block list is generated will not be shown. Core will then scoop up any remaining messages and clear the messages data so the missed messages are never seen if the theme doesn't print the $messages variable.

Attaching a patch that uses a hook_page_alter() to find the messages block and then sets the content to theme('status_messages'). The hook_page_alter() is called just before the call to drupal_render($page) so there really shouldn't be any messages that get missed.

Jax’s picture

jbylsma’s picture

The patch in #3 got me most of the way there, but it still wasn't capturing all messages. After a little research, I figured out that it would only capture the statues of modules with a lower weight, and with delta_blocks starting with "D" and having a weight of 0, that had potential to be a lot of them!

I extended #3's patch with a hook_module_implements_alter() implementation that forces delta_blocks' hook_page_alter to run last.

jbylsma’s picture

Issue summary: View changes

aaaaand again

m1r1k’s picture

Issue summary: View changes
FileSize
652 bytes

Well, I've also just met this problem. Drupal messages is a pure stack inside $_SESSION variable. And every time we're calling drupal_get_messages() or parent function theme_status_messages() we're clearing this stack.

By default most of themes has theme('status_messages') inside template_page_preprocess() or template_html_preprocess() or somewhere else. All contrib or custom themes SHOULD extend core's logic and check some settings to be available to avoid rendering messages via theme, e.g.:

  // Generate messages last in order to capture as many as possible for the
  // current page.
  if (!isset($variables['messages'])) {
    $variables['messages'] = $variables['show_messages'] ? theme('status_messages') : '';
  }

According to current Delta's implementation of status_messages block, we fetch messages inside hook_block_view():

    case 'messages':
      return theme('status_messages');

That's why any drupal message added inside hook that is invoked AFTER hook_block_view() is missed at all (because usually nobody render theme's messages output)
hook_page_build() and hook_page_alter() are examples of such 'late' hooks. I think that it's Delta's problem.

Proposed solution:
1)

    case 'messages':
      return array('content' => array('#theme' => 'status_messages'));

that will postponed calling theme_status_messages() to the latest state.
2) Remove calling theme_status_messages() via theme variable. (Most of themes have this setting, others have to add it)

thirdender’s picture

I was having this problem along with the Omega theme, but I couldn't find where Omega was actually rendering the status messages. I managed to solve the problem by overriding Omega's theme_status_messages implementation for my theme, and storing the output in a static variable. I don't know if that's the proper way to handle it, but it's working for my implementation.