You are here

protected function Message::processArguments in Message 8

Process the message given the arguments saved with it.

Parameters

array $arguments: Array with the arguments.

array $output: Array with the templated text saved in the message template.

Return value

array The templated text, with the placeholders replaced with the actual value, if there are indeed arguments.

1 call to Message::processArguments()
Message::getText in src/Entity/Message.php
Replace arguments with their placeholders.

File

src/Entity/Message.php, line 243

Class

Message
Defines the Message entity class.

Namespace

Drupal\message\Entity

Code

protected function processArguments(array $arguments, array $output) {

  // Check if we have arguments saved along with the message.
  if (empty($arguments)) {
    return $output;
  }
  foreach ($arguments as $key => $value) {
    if (is_array($value) && !empty($value['callback']) && is_callable($value['callback'])) {

      // A replacement via callback function.
      $value += [
        'pass message' => FALSE,
      ];
      if ($value['pass message']) {

        // Pass the message object as-well.
        $value['arguments']['message'] = $this;
      }
      $arguments[$key] = call_user_func_array($value['callback'], $value['arguments']);
    }
  }
  foreach ($output as $key => $value) {
    $output[$key] = new FormattableMarkup($value, $arguments);
  }
  return $output;
}