You are here

thunder.install in Thunder 8.2

Install, update and uninstall functions for the thunder installation profile.

File

thunder.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the thunder installation profile.
 */
use Drupal\Component\Utility\DiffArray;
use Drupal\Component\Utility\NestedArray;
use Drupal\update_helper\UpdateLogger;
use Drupal\views\Entity\View;
use Drupal\user\Entity\Role;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\metatag\Entity\MetatagDefaults;
use Drupal\field\Entity\FieldConfig;
use Drupal\paragraphs\Entity\Paragraph;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

/**
 * Update hook dependencies.
 *
 * 1. Dependency on Thunder Updater module.
 * 2. Ensure that Thunder updates come last so entity schema updates and more
 *    fundamental updates occur first.
 *
 * @return mixed
 *   Returns list of update hook dependencies.
 */
function thunder_update_dependencies() {
  $switchToUpdaterHelperUpdaterHook = [
    'thunder_updater' => 8001,
  ];
  $dependencies['thunder'] = [
    8006 => $switchToUpdaterHelperUpdaterHook,
  ];

  // Ensure that all thunder hook_update_N functions are called after all other
  // update hooks.
  $list = [];
  $return = [];
  $updates = update_get_update_list();

  // List of thunder modules with hook_update_N() functions.
  $thunder_module_list = [
    'thunder',
    'thunder_article',
    'thunder_liveblog',
    'thunder_media',
    'thunder_paragraphs',
    'thunder_taxonomy',
  ];
  foreach ($updates as $module => $info) {
    if (in_array($module, $thunder_module_list, TRUE)) {

      // Build a list of thunder modules with updates to run.
      $return[$module] = [];
    }
    else {

      // Build the list of all the update hooks for thunder updates to depend
      // on.
      $pending = array_keys($info['pending']);
      $list[$module] = array_pop($pending);
    }
  }

  // Add the dependencies to the thunder modules with updates to run.
  foreach ($return as $module => &$info) {
    $info[$updates[$module]['start']] = $list;
  }

  // Set a custom skip message for update taxonomy_update_8601(), because we
  // provide our own update path in thunder_taxonomy_update_8003().
  if (!empty($updates['taxonomy']['pending'][8601])) {
    \Drupal::state()
      ->set('taxonomy_update_8601_skip_message', 'This update function was skipped, because Thunder provides it\'s own update for the status field on taxonomy terms.');
  }
  return NestedArray::mergeDeepArray([
    $return,
    $dependencies,
  ], TRUE);
}

/**
 * Helper function for direct use of update helper checklist service.
 *
 * @param string $update_id
 *   Identifier of update in checklist.
 * @param bool $successful
 *   The success or failure of update.
 * @param \Drupal\update_helper\UpdateLogger $updateLogger
 *   Used update logger service in update hook.
 */
function _thunder_mark_update_checklist($update_id, $successful, UpdateLogger $updateLogger) {
  try {

    /** @var \Drupal\update_helper_checklist\UpdateChecklist $update_checklist */
    $update_checklist = \Drupal::service('update_helper_checklist.update_checklist');
    if ($successful) {
      $update_checklist
        ->markUpdatesSuccessful([
        'thunder' => [
          $update_id,
        ],
      ]);
    }
    else {
      $update_checklist
        ->markUpdatesFailed([
        'thunder' => [
          $update_id,
        ],
      ]);
    }
  } catch (EntityStorageException $ee) {
    $updateLogger
      ->warning(t('Unable to mark update in checklist.'));
  } catch (ServiceNotFoundException $se) {

    // If service is not available, we will just ignore it.
  }
}

/**
 * Adds metatag configuration.
 */
function thunder_update_8001() {
  \Drupal::service('module_installer')
    ->install([
    'config_update',
    'metatag_open_graph',
    'metatag_twitter_cards',
  ]);
  $configs = [
    'metatag_defaults' => [
      'node__article',
    ],
    'image_style' => [
      'twitter',
      'facebook',
    ],
  ];
  foreach ($configs as $entity => $ids) {
    foreach ($ids as $id) {
      try {
        \Drupal::service('config_update.config_update')
          ->import($entity, $id);
      } catch (EntityStorageException $e) {
      }
    }
  }
  $meta = MetatagDefaults::load('global');
  $tags = $meta
    ->get('tags');
  if (empty($tags['og_site_name'])) {
    $tags['og_site_name'] = '[site:name]';
  }
  if (empty($tags['twitter_cards_type'])) {
    $tags['twitter_cards_type'] = 'summary';
  }
  $meta
    ->set('tags', $tags);
  $meta
    ->save();
}

/**
 * Enable thunder_fia.
 */
function thunder_update_8002() {
  if (\Drupal::moduleHandler()
    ->moduleExists('fb_instant_articles')) {
    $modules = \Drupal::configFactory()
      ->getEditable('core.extension')
      ->get('module');
    $modules['thunder_fia'] = 1;
    \Drupal::configFactory()
      ->getEditable('core.extension')
      ->set('module', $modules)
      ->save();
  }
}

/**
 * Fix metatag config.
 */
function thunder_update_8003() {
  $sandbox = [];
  module_load_include('install', 'metatag');
  metatag_update_8102($sandbox);
  metatag_update_8103();

  // Reset the default field values.
  $entity_manager = \Drupal::service('entity.manager');

  // Get all of the field storage entities of type metatag.
  $field_storage_configs = $entity_manager
    ->getStorage('field_storage_config')
    ->loadByProperties([
    'type' => 'metatag',
  ]);
  foreach ($field_storage_configs as $field_storage) {
    $field_name = $field_storage
      ->getName();

    // Get the individual fields (field instances) associated with bundles.

    /** @var \Drupal\field\Entity\FieldConfig[] $fields */
    $fields = $entity_manager
      ->getStorage('field_config')
      ->loadByProperties([
      'field_name' => $field_name,
    ]);
    foreach ($fields as $field) {
      $field
        ->setDefaultValue(serialize([]));
      $field
        ->save();
    }
  }
}

/**
 * Require instagram and twitter url field.
 */
function thunder_update_8004() {
  $config = FieldConfig::load('media.instagram.field_url');
  if ($config) {
    $config
      ->setRequired(TRUE)
      ->save();
  }
  $config = FieldConfig::load('media.twitter.field_url');
  if ($config) {
    $config
      ->setRequired(TRUE)
      ->save();
  }
}

/**
 * Add author filter to content view.
 */
function thunder_update_8005() {

  /** @var \Drupal\views\Entity\View $view */
  $view = View::load('content');
  if (empty($view
    ->getDisplay('default')['display_options']['filters']['uid'])) {
    $uid['uid'] = [
      'id' => 'uid',
      'table' => 'node_field_data',
      'field' => 'uid',
      'relationship' => 'none',
      'group_type' => 'group',
      'admin_label' => '',
      'operator' => 'in',
      'value' => [],
      'group' => 1,
      'exposed' => TRUE,
      'expose' => [
        'operator_id' => 'uid_op',
        'label' => 'Authored by',
        'description' => '',
        'use_operator' => FALSE,
        'operator' => 'uid_op',
        'identifier' => 'uid',
        'required' => FALSE,
        'remember' => FALSE,
        'multiple' => FALSE,
        'remember_roles' => [
          'authenticated' => 'authenticated',
          'anonymous' => '0',
          'editor' => '0',
          'seo' => '0',
          'administrator' => '0',
        ],
        'reduce' => FALSE,
      ],
      'is_grouped' => FALSE,
      'group_info' => [
        'label' => '',
        'description' => '',
        'identifier' => '',
        'optional' => TRUE,
        'widget' => 'select',
        'multiple' => FALSE,
        'remember' => FALSE,
        'default_group' => 'All',
        'default_group_multiple' => [],
        'group_items' => [],
      ],
      'entity_type' => 'node',
      'entity_field' => 'uid',
      'plugin_id' => 'user_name',
    ];
    $newArray = array_slice($view
      ->getDisplay('default')['display_options']['filters'], 0, 4, TRUE) + $uid + array_slice($view
      ->getDisplay('default')['display_options']['filters'], 4, NULL, TRUE);
    $view
      ->getDisplay('default')['display_options']['filters'] = $newArray;
    $view
      ->save();
  }
}

/**
 * Adds instagram preview mode.
 */
function thunder_update_8006() {

  /** @var \Drupal\update_helper\UpdateLogger $updateLogger */
  $updateLogger = \Drupal::service('update_helper.logger');
  $configs = [
    'entity_view_display' => [
      'paragraph.instagram.preview',
      'media.instagram.thumbnail',
    ],
  ];

  /** @var Drupal\config_update\ConfigRevertInterface $configReverter */
  $configReverter = \Drupal::service('config_update.config_update');

  // Ensure that required view mode exists.
  if (empty($configReverter
    ->getFromActive('entity_view_mode', 'media.thumbnail'))) {
    $configReverter
      ->import('entity_view_mode', 'media.thumbnail');
  }

  // Import listed configurations.
  foreach ($configs as $entity => $ids) {
    foreach ($ids as $id) {
      try {
        $configReverter
          ->import($entity, $id);
      } catch (\Exception $e) {
        $updateLogger
          ->warning(t('Unable to import @entity.@id config.', [
          '@id' => $id,
          '@entity' => $entity,
        ]));
      }
    }
  }
  return $updateLogger
    ->output();
}

/**
 * Installs the responsive_preview module.
 */
function thunder_update_8101() {
  \Drupal::service('module_installer')
    ->install([
    'responsive_preview',
  ]);
}

/**
 * Installs the access_unpublished module.
 */
function thunder_update_8102() {
  \Drupal::service('module_installer')
    ->install([
    'access_unpublished',
  ]);
}

/**
 * Installs the update_helper module.
 */
function thunder_update_8103() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');

  // Now update helper is enabled and we can start using it!
  $updater
    ->executeUpdate('thunder', 'v1_1__responsive_preview');
  $updater
    ->executeUpdate('thunder', 'v1_1__access_unpublished');
  return $updater
    ->logger()
    ->output();
}

/**
 * Installs the metatag_facebook module.
 */
function thunder_update_8104() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'v1_1__metatag_facebook');
  return $updater
    ->logger()
    ->output();
}

/**
 * Installs the config_update module.
 */
function thunder_update_8105() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'v1_1__config_update');
  return $updater
    ->logger()
    ->output();
}

/**
 * Installs the diff module.
 */
function thunder_update_8106() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'v1_1__diff');
  return $updater
    ->logger()
    ->output();
}

/**
 * Installs the thunder_riddle module.
 *
 * This replaces the riddle paragraphs by a new one, using media_entity as
 * a base. After that you are able to select riddles out of the entity browser.
 */
function thunder_update_8107() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();
  $entityTypeManager = \Drupal::entityTypeManager();
  $paragraphType = $entityTypeManager
    ->getStorage('paragraphs_type')
    ->load('paragraphs_riddle_marketplace');
  $successfulUpdate = TRUE;
  if (!empty($paragraphType)) {
    if (\Drupal::service('module_installer')
      ->install([
      'thunder_riddle',
    ])) {

      // Import Riddles.
      \Drupal::service('media_riddle_marketplace')
        ->createMediaEntities();

      /** @var \Drupal\paragraphs\Entity\Paragraph[] $paragraphs */
      $paragraphs = $entityTypeManager
        ->getStorage('paragraph')
        ->loadByProperties([
        'type' => 'paragraphs_riddle_marketplace',
      ]);
      foreach ($paragraphs as $oldParagraph) {
        $fieldName = $oldParagraph
          ->get('parent_field_name')
          ->get(0)
          ->getString();
        $host = $oldParagraph
          ->getParentEntity();
        if ($host) {
          foreach ($host
            ->get($fieldName)
            ->getValue() as $delta => $field) {
            if ($field['target_id'] == $oldParagraph
              ->id()) {

              /* @var \Drupal\media_entity\Entity\Media */
              $media = $entityTypeManager
                ->getStorage('media')
                ->loadByProperties([
                'bundle' => 'riddle',
                'field_riddle_id' => pathinfo(parse_url($oldParagraph
                  ->get('field_link')->uri)['path'])['filename'],
              ]);
              $media = current($media);

              // Create new Riddle paragraph for media.
              try {
                $paragraph = Paragraph::create([
                  'type' => 'riddle',
                  'field_riddle' => $media
                    ->id(),
                ]);
                $paragraph
                  ->save();
              } catch (EntityStorageException $storageException) {
                $updateLogger
                  ->warning(t('Could not create paragraph for @riddle in @name.', [
                  '@riddle' => $media
                    ->label(),
                  '@name' => $host
                    ->label(),
                ]));
                $successfulUpdate = FALSE;

                // Since paragraph is not created - skip further execution.
                continue;
              }

              // Add new paragraph to parent entity.
              $host
                ->get($fieldName)
                ->set($delta, [
                'target_id' => $paragraph
                  ->id(),
                'target_revision_id' => $paragraph
                  ->getRevisionId(),
              ]);
              try {
                $host
                  ->save();
                $updateLogger
                  ->info(t('Converted @riddle in @name.', [
                  '@riddle' => $media
                    ->label(),
                  '@name' => $host
                    ->label(),
                ]));

                // After successful saving -> remove old paragraph.
                try {
                  $oldParagraph
                    ->delete();
                } catch (EntityStorageException $storageException) {
                  $updateLogger
                    ->warning(t('Could not delete @riddle in @name.', [
                    '@riddle' => $media
                      ->label(),
                    '@name' => $host
                      ->label(),
                  ]));
                  $successfulUpdate = FALSE;
                }
              } catch (EntityStorageException $storageException) {
                $updateLogger
                  ->warning(t('Could not convert @riddle in @name.', [
                  '@riddle' => $media
                    ->label(),
                  '@name' => $host
                    ->label(),
                ]));
                $successfulUpdate = FALSE;
              }
            }
          }
        }
      }
      if ($successfulUpdate) {
        try {
          $fieldConfigs = $entityTypeManager
            ->getStorage('field_config')
            ->loadByProperties([
            'field_type' => 'entity_reference_revisions',
          ]);
          foreach ($fieldConfigs as $field) {
            $settings = $field
              ->getSetting('handler_settings');
            unset($settings['target_bundles']['paragraphs_riddle_marketplace']);
            unset($settings['target_bundles_drag_drop']['paragraphs_riddle_marketplace']);
            $field
              ->setSetting('handler_settings', $settings);
            $field
              ->save();
          }
          $paragraphType
            ->delete();
          $updateLogger
            ->info(t('Old riddle paragraph type is successfully removed.'));
        } catch (\Exception $e) {
          $successfulUpdate = FALSE;
          $updateLogger
            ->warning(t('Removing of old riddle paragraph type has failed.'));
        }
      }
    }
    else {
      $successfulUpdate = FALSE;
      $updateLogger
        ->warning(t('Riddle module is not available.'));
    }
  }
  _thunder_mark_update_checklist('v1_1__thunder_riddle', $successfulUpdate, $updateLogger);
  return $updateLogger
    ->output();
}

/**
 * Adjust access permissions related to "access_unpublished" module.
 */
function thunder_update_8108() {

  /** @var \Drupal\update_helper\UpdateLogger $updateLogger */
  $updateLogger = \Drupal::service('update_helper.logger');

  // Granting permissions only for "anonymous" and "authenticated" user roles.
  $roles = Role::loadMultiple([
    'anonymous',
    'authenticated',
  ]);
  foreach ($roles as $role) {
    if ($role
      ->hasPermission('access content')) {
      try {
        $role
          ->grantPermission('access_unpublished node article');
        $role
          ->save();
        $updateLogger
          ->info(t('Permission for accessing unpublished node with generated token Url is granted for @user_role user role.', [
          '@user_role' => $role
            ->id(),
        ]));
      } catch (EntityStorageException $storageException) {
        $updateLogger
          ->warning(t('Unable to change permissions for @user_role user role.', [
          '@user_role' => $role
            ->id(),
        ]));
      }
    }
    else {
      $updateLogger
        ->info(t('Skipping @user_role user role, because of non-sufficient permissions.', [
        '@user_role' => $role
          ->id(),
      ]));
    }
  }

  // Output logged result of update hook execution.
  return $updateLogger
    ->output();
}

/**
 * Change paragraphs add mode to use the modal.
 */
function thunder_update_8109() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();

  /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
  $config_factory = \Drupal::configFactory();

  // List of configurations that should be checked for existence.
  $expectedConfig['content']['field_paragraphs']['settings']['add_mode'] = 'dropdown';

  // New configuration that should be applied.
  $newConfig['content']['field_paragraphs']['settings']['add_mode'] = 'modal';
  $successfulUpdate = TRUE;
  foreach ([
    'node.article',
    'taxonomy_term.channel',
    'taxonomy_term.tags',
  ] as $item) {
    $config = $config_factory
      ->getEditable('core.entity_form_display.' . $item . '.default');
    $config_data = $config
      ->get();

    // Check that configuration exists before executing update.
    if (empty($config_data)) {
      $successfulUpdate = FALSE;
      $updateLogger
        ->warning(t('Unable to adjust form display for @item default', [
        '@item' => $item,
      ]));
      continue;
    }

    // Check if configuration is already in new state.
    $merged_data = NestedArray::mergeDeep($expectedConfig, $newConfig);
    if (empty(DiffArray::diffAssocRecursive($merged_data, $config_data))) {
      $updateLogger
        ->info(t('Default form display for @item has already new configuration.', [
        '@item' => $item,
      ]));
      continue;
    }
    if (!empty($expectedConfig) && DiffArray::diffAssocRecursive($expectedConfig, $config_data)) {
      $successfulUpdate = FALSE;
      $updateLogger
        ->warning(t('Unable to adjust form display for @item default', [
        '@item' => $item,
      ]));
      continue;
    }
    $config
      ->setData(NestedArray::mergeDeep($config_data, $newConfig));
    $config
      ->save();
    $updateLogger
      ->info(t('Adjusted form display for @item default', [
      '@item' => $item,
    ]));
  }
  if (!$successfulUpdate) {
    $updateLogger
      ->warning(t('Unable to adjust paragraphs add mode.'));
  }
  _thunder_mark_update_checklist('v1_1__paragraphs_modal', $successfulUpdate, $updateLogger);
  return $updateLogger
    ->output();
}

/**
 * Adjust access permissions related to "responsive_preview" module.
 */
function thunder_update_8110() {

  /** @var \Drupal\update_helper\UpdateLogger $updateLogger */
  $updateLogger = \Drupal::service('update_helper.logger');

  // Granting permissions only for "editor" and "seo" user roles.
  $roles = Role::loadMultiple([
    'editor',
    'seo',
  ]);
  foreach ($roles as $role) {
    if ($role
      ->hasPermission('access content')) {
      try {
        $role
          ->grantPermission('access responsive preview');
        $role
          ->save();
        $updateLogger
          ->info(t('Permission for accessing responsive preview is granted for @user_role user role.', [
          '@user_role' => $role
            ->id(),
        ]));
      } catch (EntityStorageException $storageException) {
        $updateLogger
          ->warning(t('Unable to change permissions for @user_role user role.', [
          '@user_role' => $role
            ->id(),
        ]));
      }
    }
    else {
      $updateLogger
        ->info(t('Skipping @user_role user role, because of non-sufficient permissions.', [
        '@user_role' => $role
          ->id(),
      ]));
    }
  }

  // Output logged result of update hook execution.
  return $updateLogger
    ->output();
}

/**
 * Adjust permissions related to "video_embed_field" module.
 */
function thunder_update_8111() {

  /** @var \Drupal\update_helper\UpdateLogger $updateLogger */
  $updateLogger = \Drupal::service('update_helper.logger');

  // Granting permissions only for "editor" and "seo" user roles.
  $roles = Role::loadMultiple([
    'editor',
    'seo',
  ]);
  foreach ($roles as $role) {
    try {
      $role
        ->grantPermission('never autoplay videos');
      $role
        ->save();
      $updateLogger
        ->info(t('Permission for never autoplay videos is granted for @user_role user role.', [
        '@user_role' => $role
          ->id(),
      ]));
    } catch (EntityStorageException $storageException) {
      $updateLogger
        ->warning(t('Unable to change permissions for @user_role user role.', [
        '@user_role' => $role
          ->id(),
      ]));
    }
  }

  // Output logged result of update hook execution.
  return $updateLogger
    ->output();
}

/**
 * Installs new Thunder Admin theme.
 */
function thunder_update_8112() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'v1_1__thunder_admin_ux');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Enable content_lock module.
 */
function thunder_update_8113() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'v1_1__content_lock');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Enable media_entity_pinterest module.
 */
function thunder_update_8114() {
  if (\Drupal::moduleHandler()
    ->moduleExists('media_entity_pinterest')) {
    return;
  }

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'v1_1__media_entity_pinterest');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Update to Drupal 8.4.
 */
function thunder_update_8115() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();
  $successful = TRUE;
  if (!$updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8115')) {
    $successful = FALSE;
  }
  if (\Drupal::moduleHandler()
    ->moduleExists('thunder_riddle')) {
    if (!$updater
      ->executeUpdate('thunder_riddle', 'thunder__thunder_update_8115')) {
      $successful = FALSE;
    }
  }

  // TODO: ^^ Check logic of this update!?
  _thunder_mark_update_checklist('thunder__thunder_update_8115', $successful, $updateLogger);

  // Output logged messages to related channel of update execution.
  return $updateLogger
    ->output();
}

/**
 * Enable inline_form_errors module.
 */
function thunder_update_8116() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8116');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Enable paragraphs split text.
 */
function thunder_update_8117() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');

  /** @var \Drupal\update_helper\UpdateLogger $updateLogger */
  $updateLogger = $updater
    ->logger();
  if (!$updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8117')) {
    return $updateLogger
      ->output();
  }

  // Set split text functionality for basic html CKEditor mode.
  $config = \Drupal::configFactory()
    ->getEditable('editor.editor.basic_html');
  $items = $config
    ->get('settings.toolbar.rows.0');
  if ($items) {
    foreach ($items as &$item) {
      if (!empty($item['name'] && $item['name'] === 'Tools')) {
        $item['items'][] = 'SplitTextBefore';
      }
    }
    $config
      ->set('settings.toolbar.rows.0', $items)
      ->save();
  }
  else {

    // TODO: Check logic for this ESLE!!!
    $updateLogger
      ->warning('Unable to setup split text functionality for paragraphs.');
    _thunder_mark_update_checklist('thunder__thunder_update_8117', FALSE, $updateLogger);
  }

  // Output logged messages to related channel of update execution.
  return $updateLogger
    ->output();
}

/**
 * Enable admin_toolbar_links_access_filter module.
 */
function thunder_update_8118() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8118');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Enable redirect module.
 */
function thunder_update_8119() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  if (!$updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8119')) {
    return $updater
      ->logger()
      ->output();
  }
  $role = Role::load('seo');
  if ($role) {
    $role
      ->grantPermission('administer redirects');
    $role
      ->save();
  }

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Install the Configuration Selector module if necessary.
 */
function thunder_update_8120() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder_post_update_install_config_selector');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Installing paragraphs features module with corresponding settings for it.
 */
function thunder_update_8121() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8121');

  // Output logged messages to related chanel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Switch to paragraphs experimental widget.
 */
function thunder_update_8122() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');

  // Execute configuration update definition for switching to new experimental
  // paragraphs widget.
  $updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8122');

  // Output logged messages to related chanel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Remove the old paragraph split text solution.
 */
function thunder_update_8123() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();

  /** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
  $configFactory = \Drupal::configFactory();

  /** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
  $moduleHandler = \Drupal::moduleHandler();

  // Flag to keep status of update.
  $successful = TRUE;

  // We are disabling old split text plugin and uninstall split text module
  // since split text feature will be used from paragraphs_features module.
  $config = $configFactory
    ->getEditable('editor.editor.basic_html');
  if ($config) {
    $items = $config
      ->get('settings.toolbar.rows.0');
    if (!empty($items) && is_array($items)) {
      $last_item =& $items[count($items) - 1];
      if (!empty($last_item['name']) && $last_item['name'] === 'Tools' && ($split_text_index = array_search('SplitTextBefore', $last_item['items'])) !== FALSE) {
        array_splice($last_item['items'], $split_text_index, 1);
        $config
          ->set('settings.toolbar.rows.0', $items)
          ->save();
        $updateLogger
          ->info('Split before option is successfully removed from Basic HTML Editor.');
      }
      else {
        $updateLogger
          ->info('Update did not found split before option for Basic HTML Editor.');
      }
    }
    else {
      $updateLogger
        ->info('Update did not found split before option for Basic HTML Editor.');
    }
  }
  else {
    $updateLogger
      ->warning('Basic HTML Editor configuration is not available.');
  }

  // Uninstall paragraph_split_text module.
  if ($moduleHandler
    ->moduleExists('paragraph_split_text')) {

    /** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
    $moduleInstaller = \Drupal::service('module_installer');
    if ($moduleInstaller
      ->uninstall([
      'paragraph_split_text',
    ])) {
      $updateLogger
        ->info('Module "paragraph_split_text" is successfully removed.');
    }
    else {
      $updateLogger
        ->warning('Module "paragraph_split_text" is not removed.');
      $successful = FALSE;
    }
  }
  else {
    $updateLogger
      ->info('Module "paragraph_split_text" is not installed. Nothing to uninstall.');
  }

  // Update should be marked as successful only if all steps are successful.
  _thunder_mark_update_checklist('thunder__thunder_update_8123', $successful, $updateLogger);

  // Output logged messages to related chanel of update execution.
  return $updateLogger
    ->output();
}

/**
 * Adjust access permissions related to "access_unpublish" module.
 */
function thunder_update_8124() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();

  // Granting permissions only for "editor" and "seo" user roles.
  $roles = Role::loadMultiple([
    'editor',
    'seo',
  ]);
  $successful = TRUE;
  foreach ($roles as $role) {
    try {
      $role
        ->grantPermission('delete token');
      $role
        ->grantPermission('renew token');
      $role
        ->save();
      $updateLogger
        ->info(t('Permissions for deleting and renewing access tokens is granted for @user_role user role.', [
        '@user_role' => $role
          ->id(),
      ]));
    } catch (EntityStorageException $storageException) {
      $successful = FALSE;
      $updateLogger
        ->warning(t('Unable to change permissions for @user_role user role.', [
        '@user_role' => $role
          ->id(),
      ]));
    }
  }
  _thunder_mark_update_checklist('thunder__thunder_update_8124', $successful, $updateLogger);

  // Output logged result of update hook execution.
  return $updateLogger
    ->output();
}

/**
 * Empty update.
 */
function thunder_update_8125() {

  // Moved to thunder_update_8126(): seven theme was not added to thunder
  // dependencies, therefore new installations did not get it yet.
}

/**
 * Install seven theme.
 *
 * In preparation of a thunder_admin theme stable release which will use seven
 * as a base theme.
 */
function thunder_update_8126() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();

  /** @var \Drupal\Core\Extension\ThemeInstallerInterface $themeInstaller */
  $themeInstaller = \Drupal::service('theme_installer');

  // Get installed themes.
  $installedThemes = \Drupal::configFactory()
    ->getEditable('core.extension')
    ->get('theme') ?: [];
  if (array_key_exists('seven', $installedThemes)) {
    $updateLogger
      ->info('Theme "seven" has already been installed.');
    _thunder_mark_update_checklist('thunder__thunder_update_8125', TRUE, $updateLogger);
  }
  elseif ($themeInstaller
    ->install([
    'seven',
  ])) {
    $updateLogger
      ->info('Theme "seven" successfully installed.');
    _thunder_mark_update_checklist('thunder__thunder_update_8125', TRUE, $updateLogger);
  }
  else {
    $updateLogger
      ->warning('Theme "seven" not installed.');
    _thunder_mark_update_checklist('thunder__thunder_update_8125', FALSE, $updateLogger);
  }

  // Output logged result of update hook execution.
  return $updateLogger
    ->output();
}

/**
 * Enable select2 module.
 */
function thunder_update_8127() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8127');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Set metatag fields translatable per default.
 */
function thunder_update_8128() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();
  $successfulUpdate = TRUE;
  $config_ids = [
    'node.article.field_meta_tags',
    'taxonomy_term.channel.field_meta_tags',
    'taxonomy_term.tags.field_meta_tags',
  ];
  foreach ($config_ids as $config_id) {
    $config = FieldConfig::load($config_id);
    if ($config) {
      $config
        ->setTranslatable(TRUE)
        ->save();
      $updateLogger
        ->info(t('Translation is successfully enabled for @config_id configuration.', [
        '@config_id' => $config_id,
      ]));
    }
    else {
      $successfulUpdate = FALSE;
      $updateLogger
        ->warning(t('Unable to load @config_id configuration.', [
        '@config_id' => $config_id,
      ]));
    }
  }
  _thunder_mark_update_checklist('thunder__thunder_update_8128', $successfulUpdate, $updateLogger);

  // Output logged messages to related channel of update execution.
  return $updateLogger
    ->output();
}

/**
 * Structure the media edit forms.
 */
function thunder_update_8129() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8129');
  return $updater
    ->logger()
    ->output();
}

/**
 * Hide content lock messages on other forms than node edit.
 */
function thunder_update_8130() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8130');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Change the base table of the scheduler view.
 */
function thunder_update_8131() {

  /** @var \Drupal\update_helper\Updater $updateHelper */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8131');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Update image and video browser views configuration.
 */
function thunder_update_8132() {

  /** @var \Drupal\update_helper\Updater $updateHelper */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder__thunder_update_8132');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Update configurations related to previously used Thunder Updater.
 */
function thunder_update_8133() {

  /** @var \Drupal\update_helper\Updater $updateHelper */
  $updater = \Drupal::service('update_helper.updater');
  $updater
    ->executeUpdate('thunder', 'thunder_update_8133');

  // Output logged messages to related channel of update execution.
  return $updater
    ->logger()
    ->output();
}

/**
 * Use select2 widget for the author field.
 */
function thunder_update_8134() {

  /** @var \Drupal\update_helper\Updater $updateHelper */
  $updateHelper = \Drupal::service('update_helper.updater');

  // Execute configuration update definitions with logging of success.
  $updateHelper
    ->executeUpdate('thunder', 'thunder_update_8134');

  // Output logged messages to related channel of update execution.
  return $updateHelper
    ->logger()
    ->output();
}

/**
 * Updating the filter weights.
 */
function thunder_update_8135() {

  /** @var \Drupal\update_helper\Updater $updateHelper */
  $updateHelper = \Drupal::service('update_helper.updater');

  // Execute configuration update definitions with logging of success.
  $updateHelper
    ->executeUpdate('thunder', 'thunder_update_8135');

  // Output logged messages to related channel of update execution.
  return $updateHelper
    ->logger()
    ->output();
}

/**
 * Add permissions to access the tokens overview page.
 */
function thunder_update_8136() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();
  $successful = TRUE;
  foreach (Role::loadMultiple([
    'editor',
    'seo',
    'restricted_editor',
  ]) as $role) {
    try {
      if ($role
        ->hasPermission('renew token')) {
        $role
          ->grantPermission('access tokens overview');
        $role
          ->save();
        $updateLogger
          ->info(t('Permissions for accessing the tokens overview page is granted for @user_role user role.', [
          '@user_role' => $role
            ->id(),
        ]));
      }
    } catch (EntityStorageException $storageException) {
      $successful = FALSE;
      $updateLogger
        ->warning(t('Unable to change permissions for @user_role user role.', [
        '@user_role' => $role
          ->id(),
      ]));
    }
  }
  _thunder_mark_update_checklist('thunder__thunder_update_8136', $successful, $updateLogger);

  // Output logged result of update hook execution.
  return $updateLogger
    ->output();
}

/**
 * Remove thunder_updater from the update schema.
 */
function thunder_update_8137() {
  \Drupal::keyValue('system.schema')
    ->delete('thunder_updater');
}

/**
 * Thunder 3 release preparation.
 */
function thunder_update_8138() {
}

/**
 * OBSOLETE - Add missing region key to field groups in form display settings.
 */
function thunder_update_8139() {
}

/**
 * Disable paragraphs drag & drop action button.
 */
function thunder_update_8140() {

  /** @var \Drupal\update_helper\Updater $updateHelper */
  $updateHelper = \Drupal::service('update_helper.updater');

  // Execute configuration update definitions with logging of success.
  $updateHelper
    ->executeUpdate('thunder', 'thunder_update_8140');

  // Output logged messages to related channel of update execution.
  return $updateHelper
    ->logger()
    ->output();
}

/**
 * Implements hook_requirements().
 */
function thunder_requirements($phase) {

  // Bail out if we are not in 'update' phase
  // or a simpletest testing environment is present.
  if ($phase !== 'update' || drupal_valid_test_ua() !== FALSE) {
    return [];
  }
  $requirements = [];
  if (array_key_exists('paragraphs', \Drupal::moduleHandler()
    ->getModuleList())) {
    $paragraphs_schema = drupal_get_installed_schema_version('paragraphs');
    if ($paragraphs_schema < 8021) {
      $requirements['thunder'] = [
        'title' => t('Thunder'),
        'description' => t('The paragraphs version installed is too old for update. Update paragraphs module to version 1.10 before updating to latest thunder.'),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }
  return $requirements;
}

Functions

Namesort descending Description
thunder_requirements Implements hook_requirements().
thunder_update_8001 Adds metatag configuration.
thunder_update_8002 Enable thunder_fia.
thunder_update_8003 Fix metatag config.
thunder_update_8004 Require instagram and twitter url field.
thunder_update_8005 Add author filter to content view.
thunder_update_8006 Adds instagram preview mode.
thunder_update_8101 Installs the responsive_preview module.
thunder_update_8102 Installs the access_unpublished module.
thunder_update_8103 Installs the update_helper module.
thunder_update_8104 Installs the metatag_facebook module.
thunder_update_8105 Installs the config_update module.
thunder_update_8106 Installs the diff module.
thunder_update_8107 Installs the thunder_riddle module.
thunder_update_8108 Adjust access permissions related to "access_unpublished" module.
thunder_update_8109 Change paragraphs add mode to use the modal.
thunder_update_8110 Adjust access permissions related to "responsive_preview" module.
thunder_update_8111 Adjust permissions related to "video_embed_field" module.
thunder_update_8112 Installs new Thunder Admin theme.
thunder_update_8113 Enable content_lock module.
thunder_update_8114 Enable media_entity_pinterest module.
thunder_update_8115 Update to Drupal 8.4.
thunder_update_8116 Enable inline_form_errors module.
thunder_update_8117 Enable paragraphs split text.
thunder_update_8118 Enable admin_toolbar_links_access_filter module.
thunder_update_8119 Enable redirect module.
thunder_update_8120 Install the Configuration Selector module if necessary.
thunder_update_8121 Installing paragraphs features module with corresponding settings for it.
thunder_update_8122 Switch to paragraphs experimental widget.
thunder_update_8123 Remove the old paragraph split text solution.
thunder_update_8124 Adjust access permissions related to "access_unpublish" module.
thunder_update_8125 Empty update.
thunder_update_8126 Install seven theme.
thunder_update_8127 Enable select2 module.
thunder_update_8128 Set metatag fields translatable per default.
thunder_update_8129 Structure the media edit forms.
thunder_update_8130 Hide content lock messages on other forms than node edit.
thunder_update_8131 Change the base table of the scheduler view.
thunder_update_8132 Update image and video browser views configuration.
thunder_update_8133 Update configurations related to previously used Thunder Updater.
thunder_update_8134 Use select2 widget for the author field.
thunder_update_8135 Updating the filter weights.
thunder_update_8136 Add permissions to access the tokens overview page.
thunder_update_8137 Remove thunder_updater from the update schema.
thunder_update_8138 Thunder 3 release preparation.
thunder_update_8139 OBSOLETE - Add missing region key to field groups in form display settings.
thunder_update_8140 Disable paragraphs drag & drop action button.
thunder_update_dependencies Update hook dependencies.
_thunder_mark_update_checklist Helper function for direct use of update helper checklist service.