diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index b52d120..fe4ba4b 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -15,6 +15,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\HttpKernel; use Drupal\Core\KeyValueStore\KeyValueExpirableFactory; +use Drupal\Core\Render\Element; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -992,7 +993,7 @@ public function redirectForm($form_state) { */ protected function doValidateForm(&$elements, &$form_state, $form_id = NULL) { // Recurse through all children. - foreach ($this->elementChildren($elements) as $key) { + foreach (Element::children($elements) as $key) { if (isset($elements[$key]) && $elements[$key]) { $this->doValidateForm($elements[$key], $form_state); } @@ -1151,7 +1152,7 @@ protected function doValidateForm(&$elements, &$form_state, $form_id = NULL) { */ protected function setElementErrorsFromFormState(array &$elements, array &$form_state) { // Recurse through all children. - foreach ($this->elementChildren($elements) as $key) { + foreach (Element::children($elements) as $key) { if (isset($elements[$key]) && $elements[$key]) { $this->setElementErrorsFromFormState($elements[$key], $form_state); } @@ -1356,7 +1357,7 @@ public function doBuildForm($form_id, &$element, &$form_state) { // Recurse through all child elements. $count = 0; - foreach ($this->elementChildren($element) as $key) { + foreach (Element::children($element) as $key) { // Prior to checking properties of child elements, their default // properties need to be loaded. if (isset($element[$key]['#type']) && empty($element[$key]['#defaults_loaded']) && ($info = $this->getElementInfo($element[$key]['#type']))) { @@ -1762,15 +1763,6 @@ protected function drupalSetMessage($message = NULL, $type = 'status', $repeat = } /** - * Wraps element_children(). - * - * @return array - */ - protected function elementChildren(&$elements, $sort = FALSE) { - return element_children($elements, $sort); - } - - /** * Wraps drupal_html_class(). * * @return string diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php index 2374046..f9a6718 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php @@ -816,21 +816,6 @@ protected function watchdog($type, $message, array $variables = NULL, $severity /** * {@inheritdoc} */ - protected function elementChildren(&$elements, $sort = FALSE) { - $children = array(); - foreach ($elements as $key => $value) { - if ($key === '' || $key[0] !== '#') { - if (is_array($value)) { - $children[] = $key; - } - } - } - return $children; - } - - /** - * {@inheritdoc} - */ protected function drupalHtmlClass($class) { return $class; } diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php index 7d6e1bc..3857826 100644 --- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php +++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php @@ -104,6 +104,29 @@ public function testChildren() { } /** + * Tests the children() method with an invalid key. + * + * @expectedException \PHPUnit_Framework_Error + * @expectedExceptionMessage "foo" is an invalid render array key + */ + public function testInvalidChildren() { + $element = array( + 'foo' => 'bar', + ); + Element::children($element); + } + + /** + * Tests the children() method with an ignored key/value pair. + */ + public function testIgnoredChildren() { + $element = array( + 'foo' => NULL, + ); + $this->assertSame(array(), Element::children($element)); + } + + /** * Tests the visibleChildren() method. * * @param array $element