From 19e1f2f1081bef8d05814ef5a781a1781fa3bd76 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Thu, 12 Nov 2015 21:50:23 +0000 Subject: [PATCH] Issue #2605420 by IRuslan, joelpittet: Missing aria-pressed template_preprocess_details() due to lost copied attributes in Attribute --- core/lib/Drupal/Core/Template/Attribute.php | 7 ++++--- .../Drupal/Tests/Core/Common/AttributesTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 26a1793cd53..8aaac3bb004 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -117,10 +117,11 @@ class Attribute implements \ArrayAccess, \IteratorAggregate, MarkupInterface { * An AttributeValueBase representation of the attribute's value. */ protected function createAttributeValue($name, $value) { - // If the value is already an AttributeValueBase object, return it - // straight away. + // If the value is already an AttributeValueBase object, + // return a new instance of the same class, but with the new name. if ($value instanceof AttributeValueBase) { - return $value; + $class = get_class($value); + return new $class($name, $value->value()); } // An array value or 'class' attribute name are forced to always be an // AttributeArray value for consistency. diff --git a/core/tests/Drupal/Tests/Core/Common/AttributesTest.php b/core/tests/Drupal/Tests/Core/Common/AttributesTest.php index 1dafef98831..4fc57ae6f90 100644 --- a/core/tests/Drupal/Tests/Core/Common/AttributesTest.php +++ b/core/tests/Drupal/Tests/Core/Common/AttributesTest.php @@ -71,4 +71,20 @@ class AttributesTest extends UnitTestCase { } } + /** + * Test AttributeValueBase copy. + */ + public function testAttributeValueBaseCopy() { + $original_attributes = new Attribute([ + 'checked' => TRUE, + 'class' => ['who', 'is', 'on'], + 'id' => 'first', + ]); + $attributes['selected'] = $original_attributes['checked']; + $attributes['id'] = $original_attributes['id']; + $attributes = new Attribute($attributes); + $this->assertSame((string) $original_attributes, ' checked class="who is on" id="first"', 'Original boolean value used with original name.'); + $this->assertSame((string) $attributes, ' selected id="first"', 'Original boolean value used with new name.'); + } + }