public function ActivityFactory::getMessageText in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 8 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 8.2 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 8.3 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 8.4 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 8.5 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 8.6 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 8.7 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 10.3.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 10.0.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 10.1.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getMessageText()
- 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 416
Class
- ActivityFactory
- Class ActivityFactory to create Activity items based on ActivityLogs.
Namespace
Drupal\activity_creatorCode
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;
}