public static function FormElementHelper::getElementByName in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Form/FormElementHelper.php \Drupal\Core\Form\FormElementHelper::getElementByName()
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.
3 calls to FormElementHelper::getElementByName()
- FormElementHelperTest::testGetElementByName in core/
tests/ Drupal/ Tests/ Core/ Form/ FormElementHelperTest.php - Tests the getElementByName() method.
- FormElementHelperTest::testGetElementTitle in core/
tests/ Drupal/ Tests/ Core/ Form/ FormElementHelperTest.php - Tests the getElementTitle() method.
- FormErrorHandler::displayErrorMessages in core/
modules/ inline_form_errors/ src/ FormErrorHandler.php - Loops through and displays all form errors.
File
- core/
lib/ Drupal/ Core/ Form/ FormElementHelper.php, line 29 - Contains \Drupal\Core\Form\FormElementHelper.
Class
- FormElementHelper
- Provides common functionality for form elements.
Namespace
Drupal\Core\FormCode
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 [];
}