From abb19f57c3a9921f5094d2d6c45c9625f6c1559c Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Mon, 12 Sep 2016 14:18:07 +0100 Subject: [PATCH] Issue #2774195 by lauriii, claudiu.cristea: Passing attributes to field element label is not possible --- core/includes/form.inc | 2 -- .../src/Kernel/Form/FormElementLabelTest.php | 36 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 core/modules/system/tests/src/Kernel/Form/FormElementLabelTest.php diff --git a/core/includes/form.inc b/core/includes/form.inc index a2a87ba1c6f8..26e794a9a6de 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -511,8 +511,6 @@ function template_preprocess_form_element_label(&$variables) { $variables['title'] = ['#markup' => $element['#title']]; } - $variables['attributes'] = array(); - // Pass elements title_display to template. $variables['title_display'] = $element['#title_display']; diff --git a/core/modules/system/tests/src/Kernel/Form/FormElementLabelTest.php b/core/modules/system/tests/src/Kernel/Form/FormElementLabelTest.php new file mode 100644 index 000000000000..f93d461bcf58 --- /dev/null +++ b/core/modules/system/tests/src/Kernel/Form/FormElementLabelTest.php @@ -0,0 +1,36 @@ +<?php + +namespace Drupal\Tests\system\Kernel\Form; + +use Drupal\KernelTests\KernelTestBase; +use Symfony\Component\CssSelector\CssSelectorConverter; + +/** + * Tests for form_element_label theme hook. + * + * @group Form + */ +class FormElementLabelTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['system']; + + /** + * Ensures that attributes can be placed for form element label. + */ + public function testAttributes() { + $render_array = [ + '#type' => 'label', + '#attributes' => ['class' => ['kitten']], + '#title' => 'Kittens', + '#title_display' => 'above', + ]; + $css_selector_converter = new CssSelectorConverter(); + $this->render($render_array); + $elements = $this->xpath($css_selector_converter->toXPath('.kitten')); + $this->assertCount(1, $elements); + } + +} -- GitLab