You are here

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

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

Get reference to first element by name.

Parameters

array $elements: An associative array of elements.

string $name: The element's name.

Return value

array|null Reference to found element.

1 call to WebformElementHelper::getElement()
WebformSame::alterForm in src/Plugin/WebformElement/WebformSame.php
Alter an element's associated form.

File

src/Utility/WebformElementHelper.php, line 610

Class

WebformElementHelper
Helper class webform element methods.

Namespace

Drupal\webform\Utility

Code

public static function &getElement(array &$elements, $name) {
  foreach (Element::children($elements) as $element_name) {
    if ($element_name === $name) {
      return $elements[$element_name];
    }
    elseif (is_array($elements[$element_name])) {
      $child_elements =& $elements[$element_name];
      if ($element =& static::getElement($child_elements, $name)) {
        return $element;
      }
    }
  }
  $element = NULL;
  return $element;
}