ds-8.x-3.9/ds.install

ds.install
<?php

/**
 * @file
 * Display Suite install file.
 */

use Drupal\Core\Entity\Entity\EntityViewDisplay;

/**
 * Implements hook_install().
 */
function ds_install() {
  module_set_weight('ds', 1);
}

/**
 * Disable adding entity, bundle, view mode classes per display.
 */
function ds_update_8001() {

  /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
  foreach (EntityViewDisplay::loadMultiple() as $display) {
    $ds = $display->getThirdPartySetting('ds', 'layout');
    if (!empty($ds)) {
      $ds['entity_classes'] = 'old_view_mode';
      $display
        ->setThirdPartySetting('ds', 'layout', $ds)
        ->save();
    }
  }

}

/**
 * Fix ds_switch being added to each content entity.
 */
function ds_update_8002() {
  $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $entity_types = \Drupal::entityTypeManager()->getDefinitions();
  foreach ($entity_types as $entity_type_id => $entity_type) {
    if ($entity_type->getGroup() == 'content' && $entity_type_id != 'node') {
      if ($entity_definition_update_manager->getEntityType($entity_type_id)) {
        $storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('ds_switch', $entity_type_id);
        if ($storage_definition) {
          $entity_definition_update_manager->uninstallFieldStorageDefinition($storage_definition);
        }
      }
    }
  }
}

/**
 * Uninstalls Layout plugin, then enables Layout Discovery.
 */
function ds_update_8003() {
  if (\Drupal::moduleHandler()->moduleExists('layout_plugin')) {
    \Drupal::service('module_installer')->uninstall(['layout_plugin'], FALSE);
    \Drupal::service('module_installer')->install(['layout_discovery'], FALSE);
  }
}

/**
 * Makes sure Layout Discovery is enabled on update, as 8003 could have failed to do so.
 */
function ds_update_8004() {
  if (!\Drupal::moduleHandler()->moduleExists('layout_discovery')) {
    \Drupal::service('module_installer')->install(['layout_discovery'], FALSE);
  }
}

/**
 * Fix scrambled fields in the UI
 */
function ds_update_8005() {
  // Fix scrambled fields
  $entity_storage = \Drupal::service('entity_type.manager')->getStorage('entity_view_display');
  /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $entity_display */
  foreach($entity_storage->loadMultiple() as $entity_display) {
    if ($ds_config = $entity_display->getThirdPartySettings('ds')) {
      $components = $entity_display->getComponents();
      if (empty($ds_config['regions'])) {
        continue;
      }
      foreach ($ds_config['regions'] as $region_name => $fields) {
        foreach ($fields as $field_name) {
          if (isset($components[$field_name])) {
            $options = $components[$field_name];
            $options['region'] = $region_name;
            $entity_display->setComponent($field_name, $options);
          }
        }
      }
      $entity_display->save();
    }
  }
}

/**
 * Update config settings to set field bc layer to TRUE.
 */
function ds_update_8006() {
  \Drupal::configFactory()->getEditable('ds.settings')
    ->set('ft_bc', TRUE)
    ->save(TRUE);
}

/**
 * Sets the 'Exclude layout builder blocks on block field form' to FALSE.
 */
function ds_update_8007() {
  \Drupal::configFactory()->getEditable('ds.settings')
    ->set('exclude_layout_builder_blocks_on_block_field', FALSE)
    ->save(TRUE);
}

/**
 * Sets the 'Expert field template prefix/suffix textarea' setting to FALSE.
 */
function ds_update_8008() {
  \Drupal::configFactory()->getEditable('ds.settings')
    ->set('ft_expert_prefix_suffix_textarea', FALSE)
    ->save(TRUE);
}

/**
 * Convert keys using hyphens to use underscores.
 */
function ds_update_8009() {
  $config = \Drupal::configFactory()->getEditable('ds.settings');

  $keys = [
    'ft-default',
    'ft-show-colon',
    'ft-layout-builder',
  ];

  foreach ($keys as $key) {
    $new_key = str_replace('-', '_', $key);
    $config->set($new_key, $config->get($key));
    $config->clear($key);
  }

  $config->save(TRUE);
}

/**
 * Sets the 'Exclude DS layouts in Layout Builder' setting to FALSE.
 */
function ds_update_8010() {
  \Drupal::configFactory()->getEditable('ds.settings')
    ->set('exclude_ds_layout_layout_builder', FALSE)
    ->save(TRUE);
}

/**
 * Sets the 'Use DS layout images' setting to TRUE.
 */
function ds_update_8011() {
  \Drupal::configFactory()->getEditable('ds.settings')
    ->set('layout_icon_image_bc', TRUE)
    ->save(TRUE);
}

/**
 * Sets the 'Global field template BC' setting to TRUE.
 */
function ds_update_8012() {
  \Drupal::configFactory()->getEditable('ds.settings')
    ->set('ft_default_bc', TRUE)
    ->save(TRUE);
}

/**
 * Sets the 'Layout suggestion BC' setting to TRUE.
 */
function ds_update_8013() {
  \Drupal::configFactory()->getEditable('ds.settings')
    ->set('layout_suggestion_bc', TRUE)
    ->save(TRUE);
}

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

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