You are here

public function Configuration::iterate in Configuration Management 7.2

This function will exectute a callback function over all the configurations objects that it process.

Parameters

ConfigIteratorSettings $settings: A ConfigIteratorSettings instance that specifies, which is the callback to execute. If dependencies and optional configurations should be processed too, and storage the cache of already processed configurations.

See also

importToActiveStore()

exportToDataStore()

revertActiveStore()

discoverRequiredModules()

File

lib/Drupal/configuration/Config/Configuration.php, line 869
Definition of Drupal\configuration\Config\Configuration.

Class

Configuration

Namespace

Drupal\configuration\Config

Code

public function iterate(ConfigIteratorSettings &$settings) {
  $callback = $settings
    ->getCallback();
  $build_callback = $settings
    ->getBuildCallback();
  if ($settings
    ->alreadyProcessed($this) || $settings
    ->excluded($this)) {
    return;
  }

  // First proccess requires the dependencies that have to be processed before
  // load the current configuration.
  if ($settings
    ->processDependencies()) {
    foreach ($this
      ->getDependencies() as $dependency => $config_dependency) {

      // In some callbacks, the dependencies storages the full config object
      // other simply use a plain string. If the object is available, use
      // that version.
      if (is_object($config_dependency)) {
        $config = $config_dependency;
      }
      else {
        $config = $settings
          ->getFromCache($dependency);
        if (!$config) {
          $config = ConfigurationManagement::createConfigurationInstance($dependency);
        }
      }
      $config
        ->setContext($settings);
      $config
        ->{$build_callback}();
      $config
        ->iterate($settings);
    }
  }
  if ($settings
    ->alreadyProcessed($this)) {
    return;
  }

  // Now, after proccess the dependencies, proccess the current configuration.
  $this
    ->setContext($settings);
  $this
    ->{$callback}($settings);
  $settings
    ->addToCache($this);

  // After proccess the dependencies and the current configuration, proccess
  // the optionals.
  if ($settings
    ->processOptionals()) {
    foreach ($this
      ->getOptionalConfigurations() as $optional => $optional_config) {
      $config = $settings
        ->getFromCache($optional);

      // In some callbacks, the optionals storages the full config object
      // other simply use a plain string. If the object is available, use
      // that version.
      if (is_object($optional_config)) {
        $config = $optional_config;
      }
      else {
        if (!$config) {
          $config = ConfigurationManagement::createConfigurationInstance($optional);
        }
      }
      $config
        ->setContext($settings);
      $config
        ->{$build_callback}();
      $config
        ->iterate($settings);
    }
  }
}