diff --git a/lib/Drupal/views/DisplayArray.php b/lib/Drupal/views/DisplayArray.php index 521d3ab..d4e0f66 100644 --- a/lib/Drupal/views/DisplayArray.php +++ b/lib/Drupal/views/DisplayArray.php @@ -10,7 +10,7 @@ namespace Drupal\views; /** * A class which wraps the displays of a view so you can lazy-initialize them. */ -class DisplayArray implements \ArrayAccess, \Iterator { +class DisplayArray implements \ArrayAccess, \Iterator, \Countable { /** * Stores a reference to the view which has this displays attached. @@ -87,7 +87,7 @@ class DisplayArray implements \ArrayAccess, \Iterator { * Implements \ArrayAccess::offsetExists(). */ public function offsetExists($offset) { - return isset($this->display[$offset]) || $this->view->storage->display[$offset]; + return isset($this->display[$offset]) || isset($this->view->storage->display[$offset]); } /** @@ -156,4 +156,11 @@ class DisplayArray implements \ArrayAccess, \Iterator { reset($this->display); } + /** + * Implements \Countable::count(). + */ + public function count() { + return count($this->view->storage->display); + } + } diff --git a/lib/Drupal/views/Tests/ViewExecutableTest.php b/lib/Drupal/views/Tests/ViewExecutableTest.php index 9fb3fbc..a2d7f8a 100644 --- a/lib/Drupal/views/Tests/ViewExecutableTest.php +++ b/lib/Drupal/views/Tests/ViewExecutableTest.php @@ -8,6 +8,7 @@ namespace Drupal\views\Tests; use Drupal\views\ViewExecutable; +use Drupal\views\DisplayArray; use Drupal\views\Plugin\views\display\DefaultDisplay; use Drupal\views\Plugin\views\display\Page; @@ -120,8 +121,7 @@ class ViewExecutableTest extends ViewTestBase { // Tests Drupal\views\ViewExecutable::initDisplay(). $view->initDisplay(); - $count = count($view->displayHandlers); - $this->assertEqual($count, 3, format_string('Make sure all display handlers got instantiated (@count of @count_expected)', array('@count' => $count, '@count_expected' => 3))); + $this->assertTrue($view->displayHandlers instanceof DisplayArray, 'The displayHandlers property has the right class.'); // Tests the classes of the instances. $this->assertTrue($view->displayHandlers['default'] instanceof DefaultDisplay); $this->assertTrue($view->displayHandlers['page'] instanceof Page); diff --git a/lib/Drupal/views/ViewExecutable.php b/lib/Drupal/views/ViewExecutable.php index 7f47dd1..725519d 100644 --- a/lib/Drupal/views/ViewExecutable.php +++ b/lib/Drupal/views/ViewExecutable.php @@ -2190,7 +2190,7 @@ class ViewExecutable { * @return Drupal\views\Plugin\views\display\DisplayPluginBase * A reference to the new handler object. */ - public function &newDisplay($id) { + public function newDisplay($id) { // Create a handler. $this->displayHandlers[$id] = views_get_plugin('display', $this->storage->display[$id]['display_plugin']); if (empty($this->displayHandlers[$id])) {