diff --git a/src/Plugin/views/area/DisplaySwitch.php b/src/Plugin/views/area/DisplaySwitch.php index e1050af4768b0eea048913ee83c1c1784ef93bab..cb7bc3c44243c0cbf754e8c9c9f5d2c8e29feade 100644 --- a/src/Plugin/views/area/DisplaySwitch.php +++ b/src/Plugin/views/area/DisplaySwitch.php @@ -326,7 +326,7 @@ class DisplaySwitch extends AreaPluginBase { * Whether the display ID is an allowed display or not. */ protected function isAllowedDisplay($display_id) { - return $this->isPathBasedDisplay($display_id) || $this->isBlockDisplay($display_id); + return ($this->isPathBasedDisplay($display_id) || $this->isBlockDisplay($display_id)) && $this->view->displayHandlers->get($display_id)->access(); } /** diff --git a/views_display_switch.module b/views_display_switch.module index 047a8e8459997d614563a0dbc3e0c378c03efaca..91002f2e7ca8668316bf38f326e35cc6db03a938 100644 --- a/views_display_switch.module +++ b/views_display_switch.module @@ -63,13 +63,20 @@ function views_display_switch_views_pre_view(ViewExecutable $view, $display_id, $handlers = []; $handlers += $view->getHandlers('header'); $handlers += $view->getHandlers('footer'); - $plugin_ids = array_column($handlers, 'plugin_id'); - // Setting display in case a GET parameter is set. - if (in_array('display_switch', $plugin_ids)) { - $request_mode = \Drupal::request()->get('mode'); - if ($request_mode != $display_id) { - $view->setDisplay($request_mode); + foreach ($handlers as $handler) { + if ($handler['plugin_id'] === 'display_switch') { + $request_mode = \Drupal::request()->get('mode'); + if ($request_mode != $display_id) { + if (($handler['displays'][$request_mode]['enabled'] ?? FALSE) + && $view->storage->getDisplay($request_mode) + && $view->displayHandlers->get($request_mode)->access() + ) { + $view->setDisplay($request_mode); + } + } + + return; } } }