class ConfigNormalizerSort in Configuration Normalizer 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/ConfigNormalizer/ConfigNormalizerSort.php \Drupal\config_normalizer\Plugin\ConfigNormalizer\ConfigNormalizerSort
Recursively sorts a configuration array.
Plugin annotation
@ConfigNormalizer(
id = "sort",
label = @Translation("sort"),
weight = 20,
description = @Translation("Recursively sorts a configuration array."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\config_normalizer\Plugin\ConfigNormalizerBase implements ConfigNormalizerInterface
- class \Drupal\config_normalizer\Plugin\ConfigNormalizer\ConfigNormalizerSort implements ContainerFactoryPluginInterface
- class \Drupal\config_normalizer\Plugin\ConfigNormalizerBase implements ConfigNormalizerInterface
Expanded class hierarchy of ConfigNormalizerSort
Deprecated
in config_normalizer:2.0.0-alpha1 and is removed from config_normalizer:2.0.0. No replacement.
See also
https://www.drupal.org/project/config_normalizer/issues/3230398
File
- src/
Plugin/ ConfigNormalizer/ ConfigNormalizerSort.php, line 22
Namespace
Drupal\config_normalizer\Plugin\ConfigNormalizerView source
class ConfigNormalizerSort extends ConfigNormalizerBase implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public function normalize($name, array &$data, array $context) {
// Only sort if the normalization mode is default.
if ($this
->isDefaultModeContext($context)) {
// Recursively normalize and return.
$data = $this
->normalizeArray($data);
}
}
/**
* Recursively sorts an array by key.
*
* @param array $array
* An array to normalize.
*
* @return array
* An array that is sorted by key, at each level of the array, with empty
* arrays removed.
*/
protected function normalizeArray(array $array) {
foreach ($array as $key => $value) {
if (is_array($value)) {
$new = $this
->normalizeArray($value);
if (count($new)) {
$array[$key] = $new;
}
}
}
// If the array is associative, sort by key.
if (Inline::isHash($array)) {
ksort($array);
}
else {
sort($array);
}
return $array;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigNormalizerBase:: |
protected | property | The entity type manager. | |
ConfigNormalizerBase:: |
public static | function | ||
ConfigNormalizerBase:: |
protected | function | Determines whether the context reference storage is the active storage. | |
ConfigNormalizerBase:: |
protected | function | Determines whether the context has a default normalization mode. | |
ConfigNormalizerBase:: |
public | function |
Creates a new config normalizer plugin. Overrides PluginBase:: |
|
ConfigNormalizerSort:: |
public | function |
Normalizes config for comparison. Overrides ConfigNormalizerInterface:: |
|
ConfigNormalizerSort:: |
protected | function | Recursively sorts an array by key. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |