protected function processTokens(array $output, $clear, Message $message) {
    $options = [
      'clear' => $clear,
    ];

    foreach ($output as $key => $value) {
      if (is_string($value)) {
        $output[$key] = \Drupal::token()
          ->replace($value, ['message' => $message], $options);
      }
      else {
        if (isset($value['value'])) {
          $output[$key] = \Drupal::token()
            ->replace($value['value'], ['message' => $message], $options);
        }
      }
    }

    return $output;
  }