function RenderPlaceholderMessageTestController::setAndLogMessage

Same name in other branches
  1. 9 core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php \Drupal\render_placeholder_message_test\RenderPlaceholderMessageTestController::setAndLogMessage()
  2. 8.9.x core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php \Drupal\render_placeholder_message_test\RenderPlaceholderMessageTestController::setAndLogMessage()
  3. 11.x core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php \Drupal\render_placeholder_message_test\RenderPlaceholderMessageTestController::setAndLogMessage()

#lazy_builder callback; sets and prints a message.

Parameters

string $message: The message to send.

Return value

array A renderable array containing the message.

File

core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php, line 115

Class

RenderPlaceholderMessageTestController

Namespace

Drupal\render_placeholder_message_test

Code

public static function setAndLogMessage($message) {
    // Ensure that messages are rendered last even when earlier placeholders
    // suspend the Fiber, this will cause BigPipe::renderPlaceholders() to loop
    // around all of the fibers before resuming this one, then finally rendering
    // the messages when there are no other placeholders left.
    if (\Fiber::getCurrent() !== NULL) {
        \Fiber::suspend();
    }
    // Set message.
    \Drupal::messenger()->addStatus($message);
    // Print which message is expected.
    return [
        '#markup' => '<p class="logged-message">Message: ' . $message . '</p>',
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.