FormElementHelper::getElementByName

public static FormElementHelper::getElementByName($name, array $form)

Retrieves a form element.

Parameters

string $name: The name of the form element. If the #parents property of your form element is ['foo', 'bar', 'baz'] then the name is 'foo][bar][baz'.

array $form: An associative array containing the structure of the form.

Return value

array The form element.

File

core/lib/Drupal/Core/Form/FormElementHelper.php, line 24

Class

FormElementHelper
Provides common functionality for form elements.

Namespace

Drupal\Core\Form

Code

public static function getElementByName($name, array $form) {
  foreach (Element::children($form) as $key) {
    if (implode('][', $form[$key]['#parents']) === $name) {
      return $form[$key];
    }
    elseif ($element = static::getElementByName($name, $form[$key])) {
      return $element;
    }
  }
  return [];
}
doc_Drupal
2016-10-29 09:15:38
Comments
Leave a Comment

Please login to continue.