You are here

class FeaturesConfigInstaller in Features 8.3

Same name and namespace in other branches
  1. 8.4 src/FeaturesConfigInstaller.php \Drupal\features\FeaturesConfigInstaller

Class for customizing the test for pre existing configuration.

Decorates the ConfigInstaller with findPreExistingConfiguration() modified to allow Feature modules to be installed.

Hierarchy

Expanded class hierarchy of FeaturesConfigInstaller

1 string reference to 'FeaturesConfigInstaller'
features.services.yml in ./features.services.yml
features.services.yml
1 service uses FeaturesConfigInstaller
features.config.installer in ./features.services.yml
Drupal\features\FeaturesConfigInstaller

File

src/FeaturesConfigInstaller.php, line 19

Namespace

Drupal\features
View source
class FeaturesConfigInstaller extends ConfigInstaller {

  /**
   * The configuration installer.
   *
   * @var \Drupal\Core\Config\ConfigInstallerInterface
   */
  protected $configInstaller;

  /**
   * The features manager.
   *
   * @var \Drupal\features\FeaturesManagerInterface
   */
  protected $featuresManager;

  /**
   * Constructs the configuration installer.
   *
   * @param \Drupal\Core\Config\ConfigInstallerInterface $config_installer
   *   The configuration installer.
   * @param \Drupal\features\FeaturesManagerInterface $features_manager
   *   The features manager.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
   * @param \Drupal\Core\Config\StorageInterface $active_storage
   *   The active configuration storage.
   * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
   *   The typed configuration manager.
   * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
   *   The configuration manager.
   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
   *   The event dispatcher.
   * @param string $install_profile
   *   The name of the currently active installation profile.
   */
  public function __construct(ConfigInstallerInterface $config_installer, FeaturesManagerInterface $features_manager, ConfigFactoryInterface $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, ConfigManagerInterface $config_manager, EventDispatcherInterface $event_dispatcher, $install_profile) {
    parent::__construct($config_factory, $active_storage, $typed_config, $config_manager, $event_dispatcher, $install_profile);
    $this->configInstaller = $config_installer;
    $this->featuresManager = $features_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function findPreExistingConfiguration(StorageInterface $storage) {

    // Override
    // Drupal\Core\Config\ConfigInstaller::findPreExistingConfiguration().
    // Allow config that already exists coming from Features.
    $features_config = array_keys($this->featuresManager
      ->listExistingConfig());

    // Map array so we can use isset instead of in_array for faster access.
    $features_config = array_combine($features_config, $features_config);
    $existing_configuration = [];

    // Gather information about all the supported collections.
    $collection_info = $this->configManager
      ->getConfigCollectionInfo();
    foreach ($collection_info
      ->getCollectionNames() as $collection) {
      $config_to_create = array_keys($this
        ->getConfigToCreate($storage, $collection));
      $active_storage = $this
        ->getActiveStorages($collection);
      foreach ($config_to_create as $config_name) {
        if ($active_storage
          ->exists($config_name)) {

          // Test if config is part of a Feature package.
          if (!isset($features_config[$config_name])) {
            $existing_configuration[$collection][] = $config_name;
          }
        }
      }
    }
    return $existing_configuration;
  }

  /**
   * Creates configuration in a collection based on the provided list.
   *
   * @param string $collection
   *   The configuration collection.
   * @param array $config_to_create
   *   An array of configuration data to create, keyed by name.
   */
  public function createConfiguration($collection, array $config_to_create) {
    return parent::createConfiguration($collection, $config_to_create);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigInstaller::$activeStorages protected property The active configuration storages, keyed by collection.
ConfigInstaller::$configFactory protected property The configuration factory.
ConfigInstaller::$configManager protected property The configuration manager.
ConfigInstaller::$eventDispatcher protected property The event dispatcher.
ConfigInstaller::$installProfile protected property The name of the currently active installation profile.
ConfigInstaller::$isSyncing protected property Is configuration being created as part of a configuration sync.
ConfigInstaller::$sourceStorage protected property The configuration storage that provides the default configuration.
ConfigInstaller::$typedConfig protected property The typed configuration manager.
ConfigInstaller::checkConfigurationToInstall public function Checks the configuration that will be installed for an extension. Overrides ConfigInstallerInterface::checkConfigurationToInstall
ConfigInstaller::drupalGetPath protected function Wrapper for drupal_get_path().
ConfigInstaller::drupalGetProfile protected function Gets the install profile from settings.
ConfigInstaller::drupalInstallationAttempted Deprecated protected function Wrapper for drupal_installation_attempted().
ConfigInstaller::findDefaultConfigWithUnmetDependencies protected function Finds default configuration with unmet dependencies.
ConfigInstaller::getActiveStorages protected function Gets the configuration storage that provides the active configuration.
ConfigInstaller::getConfigToCreate protected function Gets configuration data from the provided storage to create.
ConfigInstaller::getDefaultConfigDirectory protected function Gets an extension's default configuration directory.
ConfigInstaller::getEnabledExtensions protected function Gets the list of enabled extensions including both modules and themes.
ConfigInstaller::getMissingDependencies protected function Returns an array of missing dependencies for a config object.
ConfigInstaller::getProfileStorages protected function Gets the profile storage to use to check for profile overrides.
ConfigInstaller::getSourceStorage public function Gets the configuration storage that provides the default configuration. Overrides ConfigInstallerInterface::getSourceStorage
ConfigInstaller::installCollectionDefaultConfig public function Installs all default configuration in the specified collection. Overrides ConfigInstallerInterface::installCollectionDefaultConfig
ConfigInstaller::installDefaultConfig public function Installs the default configuration of a given extension. Overrides ConfigInstallerInterface::installDefaultConfig
ConfigInstaller::installOptionalConfig public function Installs optional configuration. Overrides ConfigInstallerInterface::installOptionalConfig
ConfigInstaller::isSyncing public function Gets the syncing state. Overrides ConfigInstallerInterface::isSyncing
ConfigInstaller::setSourceStorage public function Sets the configuration storage that provides the default configuration. Overrides ConfigInstallerInterface::setSourceStorage
ConfigInstaller::setSyncing public function Sets the status of the isSyncing flag. Overrides ConfigInstallerInterface::setSyncing
ConfigInstaller::validateDependencies protected function Validates an array of config data that contains dependency information.
FeaturesConfigInstaller::$configInstaller protected property The configuration installer.
FeaturesConfigInstaller::$featuresManager protected property The features manager.
FeaturesConfigInstaller::createConfiguration public function Creates configuration in a collection based on the provided list. Overrides ConfigInstaller::createConfiguration
FeaturesConfigInstaller::findPreExistingConfiguration protected function Finds pre-existing configuration objects for the provided extension. Overrides ConfigInstaller::findPreExistingConfiguration
FeaturesConfigInstaller::__construct public function Constructs the configuration installer. Overrides ConfigInstaller::__construct