You are here

public function ConfigLister::listConfig in Configuration Update Manager 8

Lists the config objects in active and extension storage.

Parameters

string $list_type: Type of list to make: 'type', 'module', 'theme', or 'profile'.

string $name: Machine name of a configuration type, module, or theme to generate the list for. Ignored for profile, since that uses the active profile. Use type 'system.simple' for simple config, and 'system.all' to list all config items.

Return value

array Array whose first element is the list of config objects in active storage, second is the list of config objects in extension storage, and third is the list of optional config objects in extension storage (the ones with dependencies from config/optional directories). Note that for everything except 'type' lists, the active storage list includes all configuration items in the system, not limited to ones from this module, theme, or profile.

Overrides ConfigListInterface::listConfig

File

src/ConfigLister.php, line 137

Class

ConfigLister
Provides methods related to config listing.

Namespace

Drupal\config_update

Code

public function listConfig($list_type, $name) {
  $active_list = [];
  $install_list = [];
  $optional_list = [];
  $definitions = $this
    ->listTypes();
  switch ($list_type) {
    case 'type':
      if ($name == 'system.all') {
        $active_list = $this->activeConfigStorage
          ->listAll();
        $install_list = $this->extensionConfigStorage
          ->listAll();
        $optional_list = $this->extensionOptionalConfigStorage
          ->listAll();
      }
      elseif ($name == 'system.simple') {

        // Listing is done by prefixes, and simple config doesn't have one.
        // So list all and filter out all known prefixes.
        $active_list = $this
          ->omitKnownPrefixes($this->activeConfigStorage
          ->listAll());
        $install_list = $this
          ->omitKnownPrefixes($this->extensionConfigStorage
          ->listAll());
        $optional_list = $this
          ->omitKnownPrefixes($this->extensionOptionalConfigStorage
          ->listAll());
      }
      elseif (isset($this->definitions[$name])) {
        $definition = $this->definitions[$name];
        $prefix = $definition
          ->getConfigPrefix();
        $active_list = $this->activeConfigStorage
          ->listAll($prefix);
        $install_list = $this->extensionConfigStorage
          ->listAll($prefix);
        $optional_list = $this->extensionOptionalConfigStorage
          ->listAll($prefix);
      }
      break;
    case 'profile':
      $name = $this
        ->getProfileName();

    // Intentional fall-through here to the 'module' or 'theme' case.
    case 'module':
    case 'theme':
      $active_list = $this->activeConfigStorage
        ->listAll();
      $install_list = $this
        ->listProvidedItems($list_type, $name);
      $optional_list = $this
        ->listProvidedItems($list_type, $name, TRUE);
      break;
  }

  // This only seems to be a problem in unit tests, where a mock object
  // is returning NULL instead of an empy array for some reason.
  if (!is_array($optional_list)) {
    $optional_list = [];
  }
  return [
    $active_list,
    $install_list,
    $optional_list,
  ];
}