You are here

protected function ConfigIgnoreEventSubscriber::getIgnoredConfigs in Config Ignore 8.3

Returns the list of all ignored configs by expanding the wildcards.

Parameters

\Drupal\Core\Config\StorageInterface $storage: A config storage.

Return value

array An associative array keyed by config name and having the values either NULL, if the whole config is ignored, or an array of keys to be ignored. Each key is an array of parents:

[
  'system.site' => NULL,
  'user.settings' => [
    [
      'notify',
      'cancel_confirm',
    ],
    [
      'password_reset_timeout',
    ],
  ],
];
1 call to ConfigIgnoreEventSubscriber::getIgnoredConfigs()
ConfigIgnoreEventSubscriber::transformStorage in src/EventSubscriber/ConfigIgnoreEventSubscriber.php
Makes the import or export storages aware about ignored configs.

File

src/EventSubscriber/ConfigIgnoreEventSubscriber.php, line 213

Class

ConfigIgnoreEventSubscriber
Makes the import/export aware of ignored configs.

Namespace

Drupal\config_ignore\EventSubscriber

Code

protected function getIgnoredConfigs(StorageInterface $storage) {
  [
    $patterns,
    $exceptions,
  ] = $this
    ->getRules();
  $ignored_configs = [];
  foreach ($storage
    ->listAll() as $config_name) {
    foreach ($patterns as $ignored_config_pattern) {
      if (strpos($ignored_config_pattern, ':') !== FALSE) {

        // Some patterns are defining also a key.
        [
          $config_name_pattern,
          $key,
        ] = explode(':', $ignored_config_pattern, 2);
        $key = trim($key);
        if (strpos($key, '*') !== FALSE) {
          throw new \LogicException("The key part of the config ignore pattern cannot contain the wildcard character '*'.");
        }
      }
      else {
        $config_name_pattern = $ignored_config_pattern;
        $key = NULL;
      }
      if ($this
        ->wildcardMatch($config_name_pattern, $config_name)) {
        if ($key) {
          $ignored_configs[$config_name][] = explode('.', $key);
        }
        else {
          $ignored_configs[$config_name] = NULL;

          // As this pattern has no key we continue with the next config. Any
          // subsequent pattern with the same config but with key is covered
          // by this ignore pattern.
          break;
        }
      }
    }
  }

  // Extract the exceptions from the ignored configs.
  return array_diff_key($ignored_configs, array_flip($exceptions));
}