You are here

public function ActivityFactory::getMessageText in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  2. 8 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  3. 8.2 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  4. 8.3 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  5. 8.4 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  6. 8.5 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  7. 8.7 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  8. 8.8 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  9. 10.3.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  10. 10.0.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  11. 10.1.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
  12. 10.2.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()

Get message text.

Parameters

\Drupal\message\Entity\Message $message: Message object we get the text for.

string $langcode: The language code we try to get the translation for.

Return value

array Message text array.

1 call to ActivityFactory::getMessageText()
ActivityFactory::getFieldOutputText in modules/custom/activity_creator/src/ActivityFactory.php
Get field value for 'output_text' field from data array.

File

modules/custom/activity_creator/src/ActivityFactory.php, line 407

Class

ActivityFactory
Class ActivityFactory to create Activity items based on ActivityLogs.

Namespace

Drupal\activity_creator

Code

public function getMessageText(Message $message, $langcode = '') {

  /** @var \Drupal\message\Entity\MessageTemplate $message_template */
  $message_template = $message
    ->getTemplate();
  $message_arguments = $message
    ->getArguments();
  $message_template_text = $message_template
    ->get('text');

  // If we have a language code here we can try to get a translated text.
  if (!empty($langcode)) {
    $language_manager = \Drupal::languageManager();
    if ($language_manager instanceof ConfigurableLanguageManagerInterface) {

      // Load the language override for the message template.
      $config_translation = $language_manager
        ->getLanguageConfigOverride($langcode, 'message.template.' . $message_template
        ->id());
      $translated_text = $config_translation
        ->get('text');

      // Replace the text *only* if we have an translation available.
      if ($translated_text) {
        $message_template_text = $translated_text;
      }
    }
  }
  $output = $this
    ->processArguments($message_arguments, $message_template_text, $message);
  $token_options = $message_template
    ->getSetting('token options', []);
  if (!empty($token_options['token replace'])) {

    // Token should be processed.
    $output = $this
      ->processTokens($output, !empty($token_options['clear']), $message);
  }
  return $output;
}