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.
        // Ensure that we track $changed along the way.
        if ($this->filterNestedArray($original_data[$key], $override_data[$key])) {
          $changed = TRUE;
        }
        // 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;
}
doc_Drupal
2016-10-29 08:53:18
Comments
Leave a Comment

Please login to continue.