You are here

function social_activity_update_8002 in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  2. 8 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  3. 8.2 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  4. 8.3 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  5. 8.4 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  6. 8.5 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  7. 8.6 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  8. 8.7 modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  9. 10.3.x modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  10. 10.0.x modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  11. 10.1.x modules/social_features/social_activity/social_activity.install \social_activity_update_8002()
  12. 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 49
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();
          }
        }
      }
    }
  }
}