commercetools-8.x-1.2-alpha1/modules/commercetools_demo/commercetools_demo.install

modules/commercetools_demo/commercetools_demo.install
<?php

/**
 * @file
 * Defines the commercetools_demo module install|uninstall hooks.
 */

use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\commercetools\CommercetoolsUpdates;

/**
 * Displays a message with the configuration link.
 *
 * Implements hook_install().
 */
function commercetools_demo_install() {
  CommercetoolsUpdates::displayMessage(t("<h2>The Commercetools Demo module is ready.</h2><p>Open the @link page to set up the demo.</p>", [
    '@link' => Link::fromTextAndUrl(t('commercetools Demo'), Url::fromRoute('commercetools_demo.settings'))->toString(),
  ]));
}

/**
 * Performs cleanup on module's uninstall.
 *
 * Implements hook_uninstall().
 */
function commercetools_demo_uninstall() {
  $deployer = \Drupal::service('commercetools_demo.configuration_deployer');
  $deployer->removeDemoComponents('commercetools_content');
  $deployer->removeDemoComponents('commercetools_decoupled');
  $deployer->removeDemoComponents('commercetools_demo');
  $state = \Drupal::state();
  $state->deleteMultiple([
    'commercetools_demo',
    'commercetools_demo.ui_deployment.commercetools_demo',
    'commercetools_demo.ui_deployment.commercetools_content',
    'commercetools_demo.ui_deployment.commercetools_decoupled',
  ]);
}

/**
 * Switch on Layout builder if it's not.
 */
function commercetools_demo_update_82003(&$sandbox) {
  // Check if the Layout Builder module is not already enabled.
  if (!\Drupal::moduleHandler()->moduleExists('layout_builder')) {
    // Use the module installer service to enable the Layout Builder module.
    \Drupal::service('module_installer')->install(['layout_builder'], TRUE);
  }
}

/**
 * Deploy Commercetools demo content type with layout builder display view.
 */
function commercetools_demo_update_82004(&$sandbox) {
  $configNames = [
    'core.entity_view_display.node.commerce_products_demo.default',
    'field.field.node.commerce_products_demo.layout_builder__layout',
    'language.content_settings.node.commerce_products_demo',
    'node.type.commerce_products_demo',
    'field.storage.node.layout_builder__layout',
    'field.field.node.commerce_products_demo.layout_builder__layout',
  ];

  _commercetools_demo_config_install($configNames);
}

/**
 * Install configurations.
 *
 * @param array $configNames
 *   Names of configurations.
 * @param string $configDir
 *   Directory of configurations.
 */
function _commercetools_demo_config_install(array $configNames, string $configDir = InstallStorage::CONFIG_INSTALL_DIRECTORY) {
  $moduleExtensionList = \Drupal::service('extension.list.module');
  $configPath = $moduleExtensionList->getPath('commercetools_demo') . DIRECTORY_SEPARATOR . $configDir;
  $source = new FileStorage($configPath);
  $configInstaller = \Drupal::service('config.installer');

  foreach ($configNames as $configName) {
    if ($source->exists($configName)) {
      $configInstaller->installOptionalConfig($source);
    }
  }
}

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

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