You are here

public function FormOverrides::getConfigOverrideDiffs in Configuration Override Warn 8

Get overrides for a config.

Parameters

string $name: The name of the configuration object.

Return value

array A nested array of overridden config values, keyed by config value name. The value is an array with 'original' and 'override' values of the respective config property.

1 call to FormOverrides::getConfigOverrideDiffs()
FormOverrides::getFormOverrides in src/FormOverrides.php
Get overrides for a form.

File

src/FormOverrides.php, line 105

Class

FormOverrides
Contains logic for inspecting config forms and their overridden values.

Namespace

Drupal\config_override_warn

Code

public function getConfigOverrideDiffs($name) {
  $overrides = [];
  $config = $this->configFactory
    ->get($name);
  if ($config_overrides = $this
    ->getConfigOverrides($config)) {
    $definition = $this->typedConfigManager
      ->getDefinition($name);
    $keys = $this
      ->getConfigKeys($config_overrides, $definition);
    foreach ($keys as $key) {
      $original_value = $config
        ->getOriginal($key, FALSE);
      $override_value = $config
        ->get($key);

      // If both values are an array, run a diff on them to
      // reduce same values.
      // @todo Remove when https://www.drupal.org/project/config_override_warn/issues/2979946 is fixed.
      if (is_array($original_value) && is_array($override_value)) {
        $original_original_value = $original_value;
        $original_value = DiffArray::diffAssocRecursive($original_value, $override_value);
        $override_value = DiffArray::diffAssocRecursive($override_value, $original_original_value);
      }

      // Ignore identical overrides.
      if ($original_value === $override_value) {
        continue;
      }
      if ($this->configFactory
        ->get('config_override_warn.settings')
        ->get('show_values')) {
        $overrides[$name][$key] = [
          'original' => var_export($original_value, TRUE),
          'override' => var_export($override_value, TRUE),
        ];
      }
      else {
        $overrides[$name][$key] = NULL;
      }
    }
  }
  return $overrides;
}