You are here

public function FeaturesManager::listConfigByType in Features 8.3

Same name and namespace in other branches
  1. 8.4 src/FeaturesManager.php \Drupal\features\FeaturesManager::listConfigByType()

Lists stored configuration for a given configuration type.

Parameters

string $config_type: The type of configuration.

Overrides FeaturesManagerInterface::listConfigByType

1 call to FeaturesManager::listConfigByType()
FeaturesManager::initConfigCollection in src/FeaturesManager.php
Loads configuration from storage into a property.

File

src/FeaturesManager.php, line 1146

Class

FeaturesManager
The FeaturesManager provides helper functions for building packages.

Namespace

Drupal\features

Code

public function listConfigByType($config_type) {

  // For a given entity type, load all entities.
  if ($config_type && $config_type !== FeaturesManagerInterface::SYSTEM_SIMPLE_CONFIG) {
    $entity_storage = $this->entityTypeManager
      ->getStorage($config_type);
    $names = [];
    foreach ($entity_storage
      ->loadMultiple() as $entity) {
      $entity_id = $entity
        ->id();
      $label = $entity
        ->label() ?: $entity_id;
      $names[$entity_id] = $label;
    }
  }
  else {
    $definitions = [];
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type => $definition) {
      if ($definition
        ->entityClassImplements('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
        $definitions[$entity_type] = $definition;
      }
    }

    // Gather the config entity prefixes.
    $config_prefixes = array_map(function (EntityTypeInterface $definition) {
      return $definition
        ->getConfigPrefix() . '.';
    }, $definitions);

    // Find all config, and then filter our anything matching a config prefix.
    $names = $this->configStorage
      ->listAll();
    $names = array_combine($names, $names);
    foreach ($names as $item_name) {
      foreach ($config_prefixes as $config_prefix) {
        if (strpos($item_name, $config_prefix) === 0) {
          unset($names[$item_name]);
        }
      }
    }
  }
  return $names;
}