You are here

public static function WebformElementHelper::merge in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Utility/WebformElementHelper.php \Drupal\webform\Utility\WebformElementHelper::merge()

Merge element properties.

Parameters

array $elements: An array of elements.

array $source_elements: An array of elements to be merged.

2 calls to WebformElementHelper::merge()
WebformElementHelper::applyTranslation in src/Utility/WebformElementHelper.php
Apply translation to element.
WebformTranslationManager::getTranslationElements in src/WebformTranslationManager.php
Get flattened associative array of translated element properties.

File

src/Utility/WebformElementHelper.php, line 520

Class

WebformElementHelper
Helper class webform element methods.

Namespace

Drupal\webform\Utility

Code

public static function merge(array &$elements, array $source_elements) {
  foreach ($elements as $key => &$element) {
    if (!isset($source_elements[$key])) {
      continue;
    }
    $source_element = $source_elements[$key];
    if (gettype($element) !== gettype($source_element)) {
      continue;
    }
    if (is_array($element)) {
      self::merge($element, $source_element);
    }
    elseif (is_scalar($element)) {
      $elements[$key] = $source_element;
    }
  }
}