You are here

public static function MessageArgumentsWorker::messageArgumentsUpdate in Message UI 8

A helper function for generate a new array of the message's arguments.

Parameters

\Drupal\message\Entity\Message $message: The message which her arguments need an update.

array $arguments: The new arguments need to be calculated.

2 calls to MessageArgumentsWorker::messageArgumentsUpdate()
MessageArgumentsWorker::argumentsUpdate in src/Plugin/QueueWorker/MessageArgumentsWorker.php
The message batch or queue item callback function.
MessageArgumentsWorker::processItem in src/Plugin/QueueWorker/MessageArgumentsWorker.php
Works on a single queue item.

File

src/Plugin/QueueWorker/MessageArgumentsWorker.php, line 93

Class

MessageArgumentsWorker
Queue worker plugin instance to update the message arguments.

Namespace

Drupal\message_ui\Plugin\QueueWorker

Code

public static function messageArgumentsUpdate(Message $message, array $arguments) {
  $message_arguments = [];
  foreach ($arguments as $token) {

    // Get the hard coded value of the message and him in the message.
    $token_name = str_replace([
      '@{',
      '}',
    ], [
      '[',
      ']',
    ], $token);
    $token_service = \Drupal::token();
    $value = $token_service
      ->replace($token_name, [
      'message' => $message,
    ]);
    $message_arguments[$token] = $value;
  }
  $message
    ->setArguments($message_arguments);
  $message
    ->save();
}