diff --git a/core/lib/Drupal/Component/Utility/DeprecatedArray.php b/core/lib/Drupal/Component/Utility/DeprecatedArray.php index 88d0287232..2eb206ef58 100644 --- a/core/lib/Drupal/Component/Utility/DeprecatedArray.php +++ b/core/lib/Drupal/Component/Utility/DeprecatedArray.php @@ -5,7 +5,7 @@ /** * An array that triggers a deprecation warning when accessed. */ -class DeprecatedArray implements \ArrayAccess { +class DeprecatedArray implements \ArrayAccess, \IteratorAggregate { /** * The array values. @@ -26,7 +26,7 @@ class DeprecatedArray implements \ArrayAccess { * * @param array $values * The array values. - * @param $message + * @param string $message * The deprecation message. */ public function __construct(array $values, $message) { @@ -66,4 +66,11 @@ public function offsetUnset($offset) { unset($this->values[$offset]); } + /** + * {@inheritdoc} + */ + public function getIterator() { + return new \ArrayIterator($this->values); + } + } diff --git a/core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php b/core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php index a03e759ad3..10428a079f 100644 --- a/core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php @@ -90,6 +90,13 @@ public function testGlobalsSafety() { $this->assertEquals(30, $GLOBALS['pager_total_items'][0]); $this->assertEquals(3, $GLOBALS['pager_total'][0]); $this->assertEquals(10, $GLOBALS['pager_limits'][0]); + + // Assert array is iterable. + foreach ($GLOBALS['pager_total_items'] as $pager_id => $total_items) { + // We only have one pager. + $this->assertEquals(0, $pager_id); + $this->assertEquals(30, $total_items); + } } }