You are here

function better_messages_status_messages_lazy_builder in Better Messages 8

Lazy builder for 'status_messages'.

Improved version of StatusMessages::renderMessages() that additionally wraps the output into an overlay markup whenever necessary.

Parameters

string|null $type: Limit the messages returned by type. Defaults to NULL, meaning all types. Passed on to drupal_get_messages(). These values are supported:

  • NULL
  • 'status'
  • 'warning'
  • 'error'

Return value

array A renderable array containing the messages.

1 string reference to 'better_messages_status_messages_lazy_builder'
better_messages_status_messages_pre_render in ./better_messages.module
Pre render callback for 'status_messages' render element.

File

./better_messages.module, line 70
Better messages module file.

Code

function better_messages_status_messages_lazy_builder($type) {
  $render = StatusMessages::renderMessages($type);
  if (!empty($render)) {
    $render['#theme_wrappers'][] = 'better_messages_wrapper';
    $render['#attached']['library'][] = 'better_messages/better_messages';
    $render['#attached']['drupalSettings']['better_messages'] = \Drupal::config('better_messages.settings')
      ->get();
  }
  return $render;
}