hn-8.x-1.x-dev/hn.install

hn.install
<?php

/**
 * @file
 * This file provides updates for the HN module.
 */

use Drupal\user\Entity\Role;

/**
 * Uninstall hn_extended_view_serializer.
 */
function hn_update_8001() {
  \Drupal::service('module_installer')->uninstall(['hn_extended_view_serializer']);
}

/**
 * Add config file with cache enabled.
 */
function hn_update_8002() {
  \Drupal::configFactory()->getEditable('hn.settings')->set('cache', TRUE)->save();
}

/**
 * Migrate from rest endpoint to custom route.
 */
function hn_update_8003() {
  /** @var \Drupal\user\RoleInterface[] $roles */
  $roles = Role::loadMultiple();

  // Rename the 'restful get hn_rest_resource' permission to 'access hn'.
  $old_role = 'restful get hn_rest_resource';
  $new_role = 'access hn';
  foreach ($roles as $role) {
    if ($role->hasPermission($old_role)) {
      $role->revokePermission($old_role);
      $role->grantPermission($new_role);
    }
    $role->save();
  }

  // Disable the rest resource config, it doesn't exist anymore.
  \Drupal::configFactory()->getEditable('rest.resource.hn_rest_resource')->delete();
}

/**
 * Enable the hn_image module if the images module is enabled.
 *
 * The image normalizer is now in a separate module. When the 'image' module is
 * enabled, the hn_image module will be enabled to be backwards-compatible. The
 * module can be disabled manually when the functionality isn't needed.
 */
function hn_update_8004() {
  /** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
  $moduleHandler = \Drupal::service('module_handler');
  if (!$moduleHandler->moduleExists('image')) {
    return;
  }

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

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

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