You are here

protected function ConfigFactoryOverrideBase::filterNestedArray in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Config/ConfigFactoryOverrideBase.php \Drupal\Core\Config\ConfigFactoryOverrideBase::filterNestedArray()

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.

2 calls to ConfigFactoryOverrideBase::filterNestedArray()
ConfigFactoryOverrideBase::filterOverride in core/lib/Drupal/Core/Config/ConfigFactoryOverrideBase.php
Filters data in the override based on what is currently in configuration.
TestConfigFactoryOverrideBase::doFilterNestedArray in core/tests/Drupal/Tests/Core/Config/ConfigFactoryOverrideBaseTest.php

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;
}