diff --git a/core/modules/views/src/Plugin/views/area/View.php b/core/modules/views/src/Plugin/views/area/View.php index 4f3af1cd6a7..8ef480bfdf6 100644 --- a/core/modules/views/src/Plugin/views/area/View.php +++ b/core/modules/views/src/Plugin/views/area/View.php @@ -158,7 +158,8 @@ class View extends AreaPluginBase { $dependencies = parent::calculateDependencies(); list($view_id) = explode(':', $this->options['view_to_insert'], 2); - if ($view_id) { + // Don't call the current view, as it would result into an infinite recursion. + if ($view_id && $this->view->storage->id() != $view_id) { $view = $this->viewStorage->load($view_id); $dependencies[$view->getConfigDependencyKey()][] = $view->getConfigDependencyName(); } diff --git a/core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php b/core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php new file mode 100644 index 00000000000..fd7d49724a7 --- /dev/null +++ b/core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php @@ -0,0 +1,74 @@ +entityStorage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface'); + $this->viewHandler = new ViewAreaPlugin(array(), 'view', array(), $this->entityStorage); + $this->viewHandler->view = $this->getMockBuilder('Drupal\views\ViewExecutable') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies() { + /* @var $view_this \Drupal\views\Entity\View */ + /* @var $view_other \Drupal\views\Entity\View */ + $view_this = $this->getMock('Drupal\views\ViewEntityInterface'); + $view_this->expects($this->any())->method('getConfigDependencyKey')->willReturn('config'); + $view_this->expects($this->any())->method('getConfigDependencyName')->willReturn('view.this'); + $view_this->expects($this->any())->method('id')->willReturn('this'); + $view_other = $this->getMock('Drupal\views\ViewEntityInterface'); + $view_other->expects($this->any())->method('getConfigDependencyKey')->willReturn('config'); + $view_other->expects($this->any())->method('getConfigDependencyName')->willReturn('view.other'); + $this->entityStorage->expects($this->any()) + ->method('load') + ->willReturnMap([ + ['this', $view_this], + ['other', $view_other] + ]); + $this->viewHandler->view->storage = $view_this; + + + $this->viewHandler->options['view_to_insert'] = 'other:default'; + $this->assertArrayEquals(array('config' => array('view.other')), $this->viewHandler->calculateDependencies()); + + $this->viewHandler->options['view_to_insert'] = 'this:default'; + $this->assertArrayEquals(array(), $this->viewHandler->calculateDependencies()); + } + +}