You are here

thunder.install in Thunder 6.2.x

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\NestedArray;
use Drupal\update_helper\UpdateLogger;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\views\Entity\View;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

/**
 * Update hook dependencies.
 *
 * 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() {
  $dependencies['thunder'] = [];

  // 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',
    'thunder_translation',
    'thunder_password_policy',
    'thunder_google_analytics',
    'thunder_translation',
    'thunder_workflow',
    'thunder_ivw',
    'thunder_search',
  ];
  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;
  }
  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.
  }
}

/**
 * Implements hook_update_last_removed().
 */
function thunder_update_last_removed() {
  return 8309;
}

/**
 * Prepare the content view for the config selector.
 */
function thunder_update_8310() {

  /** @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_8310');

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

/**
 * Enable bulk editing for media images.
 */
function thunder_update_8311() {

  /** @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_8311');

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

/**
 * Clean-up bulk operations on content views.
 */
function thunder_update_8312() {

  /** @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_8312');

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

/**
 * Add image name to media type field map.
 */
function thunder_update_8313() {

  /** @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_8313');

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

/**
 * Disable xsl on sitemap.
 */
function thunder_update_8314() {

  /** @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_8314');

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

/**
 * Change to the async metatag widget.
 */
function thunder_update_8315() {

  /** @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_8315');

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

/**
 * Uninstall thunder_liveblog.
 */
function thunder_update_8316() {
  $configFactory = \Drupal::configFactory();
  $liveblogNodeConfig = $configFactory
    ->getEditable('field.field.node.liveblog.field_paragraphs');
  if (!$liveblogNodeConfig
    ->isNew()) {
    $liveblogNodeConfig
      ->clear('dependencies.enforced')
      ->save();
  }
  $liveblogStorageConfig = $configFactory
    ->getEditable('field.storage.liveblog_post.field_embed_media');
  if (!$liveblogStorageConfig
    ->isNew()) {
    $liveblogStorageConfig
      ->clear('dependencies.enforced')
      ->save();
  }

  /** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
  $moduleInstaller = \Drupal::service('module_installer');
  $moduleInstaller
    ->uninstall([
    'thunder_liveblog',
  ]);
}

/**
 * Remove thunder_article.settings.
 */
function thunder_update_8317() {
  \Drupal::configFactory()
    ->getEditable('thunder_article.settings')
    ->delete();
  $view = View::load('scheduler_scheduled_content');
  if ($view) {
    $display =& $view
      ->getDisplay('overview');
    $display['display_options']['menu']['type'] = 'none';
    $view
      ->save();
    return t('The "Scheduled" menu entry was removed.');
  }
}

Functions

Namesort descending Description
thunder_update_8310 Prepare the content view for the config selector.
thunder_update_8311 Enable bulk editing for media images.
thunder_update_8312 Clean-up bulk operations on content views.
thunder_update_8313 Add image name to media type field map.
thunder_update_8314 Disable xsl on sitemap.
thunder_update_8315 Change to the async metatag widget.
thunder_update_8316 Uninstall thunder_liveblog.
thunder_update_8317 Remove thunder_article.settings.
thunder_update_dependencies Update hook dependencies.
thunder_update_last_removed Implements hook_update_last_removed().
_thunder_mark_update_checklist Helper function for direct use of update helper checklist service.