diff options
author | Alex Pott <alex.a.pott@googlemail.com> | 2015-07-23 13:01:50 +0100 |
---|---|---|
committer | Alex Pott <alex.a.pott@googlemail.com> | 2015-07-23 13:01:50 +0100 |
commit | f678e370ff269267d3eca2d9307b46d2d41db7ee (patch) | |
tree | daa8def8122bfa9295a8144c1e860ed92eddba5f | |
parent | e8e883f9c855cd419ac045c30d6ccb7f20c9993e (diff) | |
download | drupal-f678e370ff269267d3eca2d9307b46d2d41db7ee.tar.gz drupal-f678e370ff269267d3eca2d9307b46d2d41db7ee.zip |
Issue #2536456 by mbovan, Berdir, Wim Leers, dawehner: Autocomplete is broken (its JS it not loaded)
-rw-r--r-- | core/lib/Drupal/Core/Render/Element/FormElement.php | 4 | ||||
-rw-r--r-- | core/modules/system/src/Tests/Form/ElementTest.php | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/core/lib/Drupal/Core/Render/Element/FormElement.php b/core/lib/Drupal/Core/Render/Element/FormElement.php index ab13289aa7c1..173a55cb93f5 100644 --- a/core/lib/Drupal/Core/Render/Element/FormElement.php +++ b/core/lib/Drupal/Core/Render/Element/FormElement.php @@ -128,10 +128,10 @@ abstract class FormElement extends RenderElement implements FormElementInterface $metadata = BubbleableMetadata::createFromRenderArray($element); if ($access->isAllowed()) { $element['#attributes']['class'][] = 'form-autocomplete'; - $element['#attached']['library'][] = 'core/drupal.autocomplete'; + $metadata->addAttachments(['library' => ['core/drupal.autocomplete']]); // Provide a data attribute for the JavaScript behavior to bind to. $element['#attributes']['data-autocomplete-path'] = $url->getGeneratedUrl(); - $metadata->merge($url); + $metadata = $metadata->merge($url); } $metadata ->merge(BubbleableMetadata::createFromObject($access)) diff --git a/core/modules/system/src/Tests/Form/ElementTest.php b/core/modules/system/src/Tests/Form/ElementTest.php index d7085dd621e4..6555a4f063fb 100644 --- a/core/modules/system/src/Tests/Form/ElementTest.php +++ b/core/modules/system/src/Tests/Form/ElementTest.php @@ -151,6 +151,9 @@ class ElementTest extends WebTestBase { $this->drupalLogin($user); $this->drupalGet('form-test/autocomplete'); + // Make sure that the autocomplete library is added. + $this->assertRaw('core/misc/autocomplete.js'); + $result = $this->xpath('//input[@id="edit-autocomplete-1" and contains(@data-autocomplete-path, "form-test/autocomplete-1")]'); $this->assertEqual(count($result), 1, 'Ensure that the user does have access to the autocompletion'); $result = $this->xpath('//input[@id="edit-autocomplete-2" and contains(@data-autocomplete-path, "form-test/autocomplete-2/value")]'); |