diff --git a/core/modules/views/src/Tests/ViewExecutableTest.php b/core/modules/views/src/Tests/ViewExecutableTest.php index 8492790f1dbd0238d775b631da85d0e97ec75e0b..4e69ba30f9c52e30c5dbf0407f7594f738feca76 100644 --- a/core/modules/views/src/Tests/ViewExecutableTest.php +++ b/core/modules/views/src/Tests/ViewExecutableTest.php @@ -401,6 +401,19 @@ public function testGetHandlerTypes() { } } + /** + * Tests ViewExecutable::getHandlers(). + */ + public function testGetHandlers() { + $view = Views::getView('test_executable_displays'); + $view->setDisplay('page_1'); + + $view->getHandlers('field', 'page_2'); + + // getHandlers() shouldn't change the active display. + $this->assertEqual('page_1', $view->current_display, "The display shouldn't change after getHandlers()"); + } + /** * Tests the validation of display handlers. */ diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index 64ba65936743d4c4ecc2e0ecb7e83df4ddf2c8b0..9791a887cd6072882430ae00dd1b6e72cb3ee8a7 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -2001,6 +2001,8 @@ public static function generateHandlerId($requested_id, $existing_items) { * An array of handler instances of a given type for this display. */ public function getHandlers($type, $display_id = NULL) { + $old_display_id = !empty($this->current_display) ? $this->current_display : 'default'; + $this->setDisplay($display_id); if (!isset($display_id)) { @@ -2009,7 +2011,14 @@ public function getHandlers($type, $display_id = NULL) { // Get info about the types so we can get the right data. $types = static::getHandlerTypes(); - return $this->displayHandlers->get($display_id)->getOption($types[$type]['plural']); + + $handlers = $this->displayHandlers->get($display_id)->getOption($types[$type]['plural']); + + // Restore initial display id (if any) or set to 'default'. + if ($display_id != $old_display_id) { + $this->setDisplay($old_display_id); + } + return $handlers; } /**