You are here

public function ConfigNormalizerActive::normalize in Configuration Normalizer 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/ConfigNormalizer/ConfigNormalizerActive.php \Drupal\config_normalizer\Plugin\ConfigNormalizer\ConfigNormalizerActive::normalize()

Normalizes config for comparison.

Normalization can help ensure that config from different storages can be compared meaningfully.

Parameters

string $name: The name of a configuration object to normalize.

array &$data: Configuration array to normalize.

array $context: An array of key-value pairs to pass additional context when needed.

Overrides ConfigNormalizerInterface::normalize

File

src/Plugin/ConfigNormalizer/ConfigNormalizerActive.php, line 26

Class

ConfigNormalizerActive
Normalizes configuration potentially saved to the active storage.

Namespace

Drupal\config_normalizer\Plugin\ConfigNormalizer

Code

public function normalize($name, array &$data, array $context) {
  if ($this
    ->isActiveStorageContext($context) && ($active_data = $context['reference_storage_service']
    ->read($name))) {

    // system.site.uuid may be set but empty.
    if (isset($data['uuid']) && empty($data['uuid'])) {
      unset($data['uuid']);
    }

    // Merge in uuid and _core while retaining the key order.
    $merged = array_replace($active_data, $data);
    $data = array_intersect_key($merged, array_flip(array_merge(array_keys($data), [
      'uuid',
      '_core',
    ])));
  }
}