You are here

class FeaturesExtensionStorages in Features 8.3

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

Wraps FeaturesInstallStorage to support multiple configuration directories.

Hierarchy

Expanded class hierarchy of FeaturesExtensionStorages

File

src/FeaturesExtensionStorages.php, line 12

Namespace

Drupal\features
View source
class FeaturesExtensionStorages implements FeaturesExtensionStoragesInterface {

  /**
   * The target storage.
   *
   * @var \Drupal\Core\Config\StorageInterface
   */
  protected $configStorage;

  /**
   * The extension storages.
   *
   * @var \Drupal\Core\Config\StorageInterface[]
   */
  protected $extensionStorages;

  /**
   * Configuration provided by extension storages.
   *
   * @var array
   */
  protected $configurationLists;

  /**
   * Constructs a new FeaturesExtensionStorages object.
   *
   * @param \Drupal\Core\Config\StorageInterface $config_storage
   *   The configuration storage.
   */
  public function __construct(StorageInterface $config_storage) {
    $this->configStorage = $config_storage;
  }

  /**
   * {@inheritdoc}
   */
  public function getExtensionStorages() {
    return $this->extensionStorages;
  }

  /**
   * {@inheritdoc}
   */
  public function addStorage($directory = InstallStorage::CONFIG_INSTALL_DIRECTORY) {
    $this->extensionStorages[$directory] = new FeaturesInstallStorage($this->configStorage, $directory);
    $this
      ->reset();
  }

  /**
   * {@inheritdoc}
   */
  public function read($name) {
    $list = $this
      ->listAllByDirectory('');
    if (isset($list[$name])) {
      $directory = $list[$name];
      return $this->extensionStorages[$directory]
        ->read($name);
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function listAll($prefix = '') {
    return array_keys($this
      ->listAllByDirectory($prefix));
  }

  /**
   * {@inheritdoc}
   */
  public function listExtensionConfig(Extension $extension) {
    $extension_config = [];
    foreach ($this->extensionStorages as $directory => $extension_storage) {
      $extension_config = array_merge($extension_config, array_keys($extension_storage
        ->getComponentNames([
        $extension
          ->getName() => $extension,
      ])));
    }
    return $extension_config;
  }

  /**
   * Resets packages and configuration assignment.
   */
  protected function reset() {
    $this->configurationLists = [];
  }

  /**
   * Returns a list of all configuration available from extensions.
   *
   * @param string $prefix
   *   (optional) The prefix to search for. If omitted, all configuration object
   *   names that exist are returned.
   *
   * @return array
   *   An array with configuration item names as keys and configuration
   *   directories as values.
   */
  protected function listAllByDirectory($prefix = '') {
    if (!isset($this->configurationLists[$prefix])) {
      $this->configurationLists[$prefix] = [];
      foreach ($this->extensionStorages as $directory => $extension_storage) {
        $this->configurationLists[$prefix] += array_fill_keys($extension_storage
          ->listAll($prefix), $directory);
      }
    }
    return $this->configurationLists[$prefix];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeaturesExtensionStorages::$configStorage protected property The target storage.
FeaturesExtensionStorages::$configurationLists protected property Configuration provided by extension storages.
FeaturesExtensionStorages::$extensionStorages protected property The extension storages.
FeaturesExtensionStorages::addStorage public function Adds a storage. Overrides FeaturesExtensionStoragesInterface::addStorage
FeaturesExtensionStorages::getExtensionStorages public function Returns all registered extension storages. Overrides FeaturesExtensionStoragesInterface::getExtensionStorages
FeaturesExtensionStorages::listAll public function Gets configuration object names starting with a given prefix. Overrides FeaturesExtensionStoragesInterface::listAll
FeaturesExtensionStorages::listAllByDirectory protected function Returns a list of all configuration available from extensions. 1
FeaturesExtensionStorages::listExtensionConfig public function Lists names of configuration objects provided by a given extension. Overrides FeaturesExtensionStoragesInterface::listExtensionConfig
FeaturesExtensionStorages::read public function Reads configuration data from the storages. Overrides FeaturesExtensionStoragesInterface::read
FeaturesExtensionStorages::reset protected function Resets packages and configuration assignment.
FeaturesExtensionStorages::__construct public function Constructs a new FeaturesExtensionStorages object.