You are here

config_selector.module in Configuration selector 8

Same filename and directory in other branches
  1. 8.2 config_selector.module

This is the Configuration Selector module.

File

config_selector.module
View source
<?php

/**
 * @file
 * This is the Configuration Selector module.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function config_selector_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.config_selector':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Configuration Selector module allows modules and install profiles to provide multiple versions of optional configuration.') . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Managing sets of configuration') . '</dt>';
      $output .= '<dd>' . t('For example, if you want to provide a view that lists content that integrates with search_api or content_lock or both or neither. You can provide 4 different views in config/optional and as different dependencies are installed views are enabled and disabled according to a priority set with the configuration. Which configuration is enabled can be managed via the <a href=":ui_url">user interface</a>.', [
        ':ui_url' => \Drupal::url('entity.config_selector_feature.collection'),
      ]) . '</dd>';
      $output .= '</dl>';
      return $output;
    case 'entity.config_selector_feature.manage':
      $output = '<p>' . t('Select which configuration entity is enabled as part of the feature. Selecting a disabled configuration entity will disable the currently selected.') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_module_preinstall().
 */
function config_selector_module_preinstall($module) {
  \Drupal::service('config_selector')
    ->setCurrentConfigList($module);
}

/**
 * Implements hook_modules_installed().
 */
function config_selector_modules_installed($modules) {
  \Drupal::service('config_selector')
    ->selectConfig();
}

/**
 * Implements hook_module_preuninstall().
 */
function config_selector_module_preuninstall($module) {
  \Drupal::service('config_selector')
    ->setUninstallConfigList($module);
}

/**
 * Implements hook_modules_uninstalled().
 */
function config_selector_modules_uninstalled($modules) {
  \Drupal::service('config_selector')
    ->selectConfigOnUninstall();
}

/**
 * Implements hook_module_implements_alter().
 */
function config_selector_module_implements_alter(&$implementations, $hook) {

  // We try to ensure that our pre install/uninstall hooks happen before any
  // other modules and our post install/uninstall hooks happen after. This means
  // that if any other implementations after any configuration we should take
  // this into account.
  switch ($hook) {

    // Move our hook_module_preinstall() and hook_module_preuninstall()
    // implementations to the end of the list.
    case 'module_preinstall':
    case 'module_preuninstall':
      $group = $implementations['config_selector'];
      $implementations = [
        'config_selector' => $group,
      ] + $implementations;
      break;

    // Move our hook_modules_installed() and hook_modules_uninstalled()
    // implementations to the end of the list.
    case 'modules_installed':
    case 'modules_uninstalled':
      $group = $implementations['config_selector'];
      unset($implementations['config_selector']);
      $implementations['config_selector'] = $group;
      break;
  }
}