openfed-8.x-8.5/modules/openfed_features/openfed_multilingual/openfed_multilingual.install

modules/openfed_features/openfed_multilingual/openfed_multilingual.install
<?php
/**
 * @file
 * Contains install and update functions for Openfed Multilingual.
 */

/**
 * Implements hook_install().
 */
function openfed_multilingual_install() {
  // Enable content translation using the proper service before importing the
  // configurations. This will avoid wrong schemas after the import.
  /** @var \Drupal\content_translation\ContentTranslationManager $content_translation */
  $content_translation = \Drupal::service('content_translation.manager');

  $translatables = [
    'node' => ['page'],
    'media' => ['iframe', 'javascript', 'svg'],
  ];
  foreach ($translatables as $entity_type => $bundles) {
    foreach ($bundles as $bundle) {
      try {
        $content_translation->setEnabled($entity_type, $bundle, 'true');
      }
      catch (\LogicException $e) {
        // This likely means we are installing from configuration and the
        // appropriate configuration has not been installed yet.
      }
    }
  }

  // Discover all the module configurations that we'll use to override existing
  // ones.
  $module = basename(__FILE__, '.install');
  $module_configs = \Drupal::configFactory()->listAll($module);

  // Overriding existing configurations.
  if (!empty($module_configs)) {
    foreach ($module_configs as $module_config_name) {
      $config = \Drupal::configFactory()->getEditable($module_config_name);
      // All the configurations set in this module starting with the module name
      // are overrides of the an already existing config. Here we'll get the
      // exiting config name.
      $existing_config = str_replace($module . '.', '', $module_config_name);
      $existing_config = \Drupal::configFactory()
        ->getEditable($existing_config);
      $existing_config->setData($config->get())->save();
      // We don't need to keep this config.
      $config->delete();
    }
  }

  // Set "/en" as the default path prefix for English language
  \Drupal::configFactory()
    ->getEditable('language.negotiation')
    ->set('url.prefixes.en', 'en')
    ->save(TRUE);

}

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

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