function social_activity_update_8002 in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 8 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 8.2 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 8.3 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 8.4 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 8.5 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 8.7 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 8.8 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 10.3.x modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 10.0.x modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 10.1.x modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
- 10.2.x modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
Update all existing Message Templates to work with newest Message version.
File
- modules/
social_features/ social_activity/ social_activity.install, line 133 - The Social activity install.
Code
function social_activity_update_8002() {
$templates = MessageTemplate::loadMultiple();
if (!empty($templates)) {
foreach ($templates as $name => $template) {
$new_text = [];
// Check if text is in the wrong format.
if (!empty($text_array = $template
->get('text'))) {
foreach ($text_array as $text) {
if (is_string($text)) {
$new_text[] = [
'format' => 'full_html',
'value' => $text,
];
}
}
// If all text was ok this would be empty,
// no need to update in that case.
if (!empty($new_text)) {
$templates[$name]
->set('text', $new_text);
$templates[$name]
->save();
$config_name = "message.template.{$template->getConfigTarget()}";
$config = \Drupal::service('config.factory')
->getEditable($config_name);
if (!empty($config)) {
$config
->set('text', $new_text);
$config
->save();
}
}
}
}
}
}