protected function ConfigFactoryOverrideBase::filterNestedArray

protected ConfigFactoryOverrideBase::filterNestedArray(array $original_data, array &$override_data)

Filters data in nested arrays.

Parameters

array $original_data: Original data array to filter against.

array $override_data: Override data to filter.

Return value

bool TRUE if $override_data was changed, FALSE otherwise.

File

core/lib/Drupal/Core/Config/ConfigFactoryOverrideBase.php, line 87

Class

ConfigFactoryOverrideBase
Defines a base event listener implementation configuration overrides.

Namespace

Drupal\Core\Config

Code

protected function filterNestedArray(array $original_data, array &$override_data) {
  $changed = FALSE;
  foreach ($override_data as $key => $value) {
    if (!isset($original_data[$key])) {
      // The original data is not there anymore, remove the override.
      unset($override_data[$key]);
      $changed = TRUE;
    }
    elseif (is_array($override_data[$key])) {
      if (is_array($original_data[$key])) {
        // Do the filtering one level deeper.
        $changed = $this->filterNestedArray($original_data[$key], $override_data[$key]);
        // If no overrides are left under this level, remove the level.
        if (empty($override_data[$key])) {
          unset($override_data[$key]);
          $changed = TRUE;
        }
      }
      else {
        // The override is an array but the value is not, this will not go
        // well, remove the override.
        unset($override_data[$key]);
        $changed = TRUE;
      }
    }
  }
  return $changed;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!ConfigFactoryOverrideBase.php/function/ConfigFactoryOverrideBase::filterNestedArray/8.1.x