summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-02-06 20:01:47 +0000
committerAlex Pott2017-02-06 20:01:47 +0000
commitba06831005484d771e06c672fca7747124381bb5 (patch)
tree591725a5bef287ee483f3562ab4011a6862b9905
parent1ff29a38738de8a8845c29e4e375ebba2b5d9a9b (diff)
Issue #2847611 by dawehner, webflo: \Drupal\Core\Template\TwigExtension::getLink overrides existing classes
-rw-r--r--core/lib/Drupal/Core/Template/TwigExtension.php5
-rw-r--r--core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php12
2 files changed, 13 insertions, 4 deletions
diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php
index 7d67ff9..62ad45d 100644
--- a/core/lib/Drupal/Core/Template/TwigExtension.php
+++ b/core/lib/Drupal/Core/Template/TwigExtension.php
@@ -284,10 +284,7 @@ class TwigExtension extends \Twig_Extension {
if ($attributes instanceof Attribute) {
$attributes = $attributes->toArray();
}
- if ($existing_attributes = $url->getOption('attributes')) {
- $attributes = array_merge($existing_attributes, $attributes);
- }
- $url->setOption('attributes', $attributes);
+ $url->mergeOptions(['attributes' => $attributes]);
}
// The text has been processed by twig already, convert it to a safe object
// for the render system.
diff --git a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
index 396b2f9..fe9f6e6 100644
--- a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
+++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
@@ -8,6 +8,7 @@ use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Template\Loader\StringLoader;
use Drupal\Core\Template\TwigEnvironment;
use Drupal\Core\Template\TwigExtension;
+use Drupal\Core\Url;
use Drupal\Tests\UnitTestCase;
/**
@@ -345,6 +346,17 @@ class TwigExtensionTest extends UnitTestCase {
$this->assertEquals($expected, $result);
}
+ /**
+ * @covers ::getLink
+ */
+ public function testLinkWithOverriddenAttributes() {
+ $url = Url::fromRoute('<front>', [], ['attributes' => ['class' => ['foo']]]);
+
+ $build = $this->systemUnderTest->getLink('test', $url, ['class' => ['bar']]);
+
+ $this->assertEquals(['foo', 'bar'], $build['#url']->getOption('attributes')['class']);
+ }
+
}
class TwigExtensionTestString {