contacts-8.x-1.x-dev/modules/group/contacts_group.install

modules/group/contacts_group.install
<?php

/**
 * @file
 * Install file for the contacts_group module.
 */

use Drupal\Core\Config\FileStorage;

/**
 * Implements hook_modules_installed().
 */
function contacts_group_modules_installed($modules, $is_syncing) {
  if (!$is_syncing) {
    if (in_array('contacts_group', $modules)) {
      // After contacts_group has been installed
      // install additional config conditionally depending on
      // whether group 2.x or group 3.x is installed.
      // This is necessary for the `contacts_orgs` view as its config schema
      // is different depending on group 2 or 3, but unlike the other
      // conditional config in this module the 2 versions of the view
      // have to have the same id, so manually install the copy we want.
      /** @var \Drupal\Core\Extension\ModuleExtensionList $module_extension_list */
      $module_extension_list = \Drupal::service('extension.list.module');
      $contacts_group_path = DRUPAL_ROOT . '/' . $module_extension_list->getPath('contacts_group');
      $group_version = $module_extension_list->getExtensionInfo('group')['version'] ?? '0';

      $config_path = NULL;
      if (version_compare($group_version, '3.0.0', '>=')) {
        $config_path = 'group_3_additional_config';
      }
      elseif (version_compare($group_version, '2.0.0', '>=')) {
        $config_path = 'group_2_additional_config';
      }

      if ($config_path) {
        $config_path = $contacts_group_path . '/config/' . $config_path;
        $source = new FileStorage($config_path);
        /** @var \Drupal\Core\Config\CachedStorage $config_storage */
        $config_storage = \Drupal::service('config.storage');
        $config_storage->write('views.view.contacts_orgs', $source->read('views.view.contacts_orgs'));
      }
    }
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc