diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index b2196245fa1748b797c2be461c48905f50927ff8..076cfd3485c2025cf1620b336a2c64a149453347 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -7,8 +7,6 @@ namespace Drupal\Core\Template; -use ArrayAccess; -use IteratorAggregate; /** * A class that can be used for collecting then rendering HTML attributtes. @@ -32,7 +30,7 @@ * // Produces <cat class="cat black-cat white-cat black-white-cat" id="socks"> * @endcode */ -class Attribute implements ArrayAccess, IteratorAggregate { +class Attribute implements \ArrayAccess, \IteratorAggregate { /** * Stores the attribute data. @@ -129,7 +127,7 @@ public function __clone() { * Implements IteratorAggregate::getIterator(). */ public function getIterator() { - return new ArrayIterator($this->storage); + return new \ArrayIterator($this->storage); } /** diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index d4f87713c48dbcb9815c73c5c2699e8ed9e4bc2b..d3521e03b4e6d3d0db9ae2954582cbd0d6bc8029 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -7,8 +7,6 @@ namespace Drupal\Core\Template; -use ArrayAccess; -use IteratorAggregate; /** * A class that defines a type of Attribute that can be added to as an array. @@ -28,7 +26,7 @@ * * @see Drupal\Core\Template\Attribute */ -class AttributeArray extends AttributeValueBase implements ArrayAccess, IteratorAggregate { +class AttributeArray extends AttributeValueBase implements \ArrayAccess, \IteratorAggregate { /** * Implements ArrayAccess::offsetGet(). @@ -75,7 +73,7 @@ public function __toString() { * Implements IteratorAggregate::getIterator(). */ public function getIterator() { - return new ArrayIterator($this->value); + return new \ArrayIterator($this->value); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php index 894e0abf32c58b648f487999c0a60c7da8567e67..6910f7ad61f6fe3653e85207ca271625ffed3390 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php @@ -47,5 +47,11 @@ function testDrupalAttributes() { // Verify empty attributes array is rendered. $this->assertIdentical((string) new Attribute(array()), '', 'Empty attributes array.'); + + $attributes_array = array('key1' => 'value1'); + $attribute = new Attribute($attributes_array); + foreach($attribute as $value) { + $this->assertIdentical((string) $value, 'value1', 'Iterate over attribute.'); + } } }