You are here

slick_media.install in Slick Media 8.3

Installation actions for Slick media.

File

slick_media.install
View source
<?php

/**
 * @file
 * Installation actions for Slick media.
 */

/**
 * Helper function to rename config dependencies.
 *
 * @param string $dependency_type
 *   The type of the dependency, such as "module" or "config".
 * @param string $dependency_id
 *   The name of the dependency to be updated.
 * @param callable $map
 *   A callback to be passed to array_map() to actually perform the config name
 *   substitution.
 */
function _slick_media_fix_dependencies($dependency_type, $dependency_id, callable $map) {
  $dependents = \Drupal::service('config.manager')
    ->findConfigEntityDependents($dependency_type, [
    $dependency_id,
  ]);
  $key = 'dependencies.' . $dependency_type;
  $key2 = 'dependencies.enforced.' . $dependency_type;
  foreach (array_keys($dependents) as $name) {
    $config = \Drupal::configFactory()
      ->getEditable($name);
    $dependencies = $config
      ->get($key);
    if (is_array($dependencies)) {
      $config
        ->set($key, array_map($map, $dependencies));
    }
    $dependencies2 = $config
      ->get($key2);
    if (is_array($dependencies2)) {
      $config
        ->set($key2, array_map($map, $dependencies2));
    }
    $config
      ->save();
  }
}

/**
 * Replace Slick Media with the main module Slick Media, and uninstall this.
 */
function slick_media_update_8301() {

  // Move all module dependencies on existing config entities from
  // "slick_media" to "slick".
  _slick_media_fix_dependencies('module', 'slick_media', function ($module) {
    return $module === 'slick_media' ? 'slick' : $module;
  });

  // Uninstall Slick Media.
  \Drupal::service('module_installer')
    ->uninstall([
    'slick_media',
  ]);

  // @todo This can be removed when
  //   https://www.drupal.org/project/drupal/issues/3063734 lands.
  // Remove slick_media from the update schema list.
  drupal_register_shutdown_function(function () {
    \Drupal::keyValue('system.schema')
      ->delete('slick_media');
  });
}

Functions

Namesort descending Description
slick_media_update_8301 Replace Slick Media with the main module Slick Media, and uninstall this.
_slick_media_fix_dependencies Helper function to rename config dependencies.