You are here

protected function SensorManager::mergeSettingsArrays in Monitoring 7

Merges settings arrays.

Based on drupal_array_merge_deep_array() but with the additional special case that flat arrays (arrays that don't have other arrays as values) are replaced, not merged.

That allows to expose settings forms for multiple values that can override the default configuration.

Parameters

$arrays: List of arrays to merge, later arrays replace keys in the previous.

Return value

array The merged array.

1 call to SensorManager::mergeSettingsArrays()
SensorManager::mergeSettings in lib/Drupal/monitoring/Sensor/SensorManager.php
Merges provided sensor settings with saved settings.

File

lib/Drupal/monitoring/Sensor/SensorManager.php, line 302
Contains \Drupal\monitoring\Sensor\SensorManager.

Class

SensorManager
Manages sensor definitions and settings.

Namespace

Drupal\monitoring\Sensor

Code

protected function mergeSettingsArrays($arrays) {
  $result = array();
  foreach ($arrays as $array) {
    foreach ($array as $key => $value) {

      // Renumber integer keys as array_merge_recursive() does. Note that PHP
      // automatically converts array keys that are integer strings (e.g., '1')
      // to integers.
      if (is_integer($key)) {
        $result[] = $value;
      }
      elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value) && $this
        ->isFlatArray($result[$key])) {
        $result[$key] = $value;
      }
      elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
        $result[$key] = $this
          ->mergeSettingsArrays(array(
          $result[$key],
          $value,
        ));
      }
      else {
        $result[$key] = $value;
      }
    }
  }
  return $result;
}