Issue #2605420 by IRuslan, joelpittet: Missing aria-pressed template_preprocess_details() due to lost copied attributes in Attribute

8.0.x
Nathaniel Catchpole 2015-11-12 21:50:23 +00:00
parent 1f0466c48c
commit 19e1f2f108
2 changed files with 20 additions and 3 deletions

View File

@ -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.

View File

@ -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.');
}
}