You are here

trait ConfigImporterTrait in Configuration Split 2.0.x

The ConfigImporterTrait helps us to create a ConfigImporter.

This uses \Drupal::getContainer() so that we don't have to inject all the services necessary to instantiate the config importer. This means we can not unit test the class, but honestly when a config importer is needed a functional test is necessary anyway.

@internal This is not an API, copy this code if you want to re-use it.

Hierarchy

2 files declare their use of ConfigImporterTrait
ConfigImportFormTrait.php in src/Form/ConfigImportFormTrait.php
ConfigSplitCliService.php in src/ConfigSplitCliService.php

File

src/Config/ConfigImporterTrait.php, line 20

Namespace

Drupal\config_split\Config
View source
trait ConfigImporterTrait {

  /**
   * Get a config importer from a storage comparer.
   *
   * @param \Drupal\Core\Config\StorageComparerInterface $storageComparer
   *   A storage comparer to pass to the config importer.
   *
   * @return \Drupal\Core\Config\ConfigImporter
   *   The config importer.
   */
  protected function getConfigImporterFromComparer(StorageComparerInterface $storageComparer) : ConfigImporter {
    $container = \Drupal::getContainer();
    return new ConfigImporter($storageComparer, $container
      ->get('event_dispatcher'), $container
      ->get('config.manager'), $container
      ->get('lock.persistent'), $container
      ->get('config.typed'), $container
      ->get('module_handler'), $container
      ->get('module_installer'), $container
      ->get('theme_handler'), $container
      ->get('string_translation'), $container
      ->get('extension.list.module'));
  }

  /**
   * Get a config importer from a storage to sync import.
   *
   * @param \Drupal\Core\Config\StorageInterface $toImport
   *   The config storage to import from.
   *
   * @return \Drupal\Core\Config\ConfigImporter
   *   The config importer.
   */
  protected function getConfigImporterFromStorage(StorageInterface $toImport) : ConfigImporter {
    $active = \Drupal::getContainer()
      ->get('config.storage');
    return $this
      ->getConfigImporterFromComparer(new StorageComparer($toImport, $active));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigImporterTrait::getConfigImporterFromComparer protected function Get a config importer from a storage comparer.
ConfigImporterTrait::getConfigImporterFromStorage protected function Get a config importer from a storage to sync import.