diff --git a/application/controllers/HostsController.php b/application/controllers/HostsController.php index a0c82214..83bb1804 100644 --- a/application/controllers/HostsController.php +++ b/application/controllers/HostsController.php @@ -64,7 +64,11 @@ class HostsController extends Controller ], ['host.state.severity DESC', 'host.state.last_state_change DESC'] ); - $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); + $viewModeSwitcher = $this->createViewModeSwitcher( + $paginationControl, + $limitControl, + viewModeSwitcherClass: TabularViewModeSwitcher::class + ); $columns = $this->createColumnControl($hosts, $viewModeSwitcher); $searchBar = $this->createSearchBar($hosts, [ @@ -292,11 +296,6 @@ class HostsController extends Controller return new FeatureStatus('host', $summary->first()); } - protected function getViewModeSwitcherInstance(): ViewModeSwitcher - { - return new TabularViewModeSwitcher(); - } - protected function getDefaultColumns(): string { return 'host.name, host.state.output'; diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index 987e538b..a0a254e2 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -75,7 +75,11 @@ class ServicesController extends Controller ], ['service.state.severity DESC', 'service.state.last_state_change DESC'] ); - $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); + $viewModeSwitcher = $this->createViewModeSwitcher( + $paginationControl, + $limitControl, + viewModeSwitcherClass: TabularViewModeSwitcher::class + ); $columns = $this->createColumnControl($services, $viewModeSwitcher); $searchBar = $this->createSearchBar($services, [ @@ -461,11 +465,6 @@ class ServicesController extends Controller return new FeatureStatus('service', $summary->first()); } - protected function getViewModeSwitcherInstance(): ViewModeSwitcher - { - return new TabularViewModeSwitcher(); - } - protected function prepareSearchFilter(Query $query, string $search, Filter\Any $filter, array $additionalColumns) { if ($this->params->shift('_hostFilterOnly', false)) { diff --git a/library/Icingadb/Web/Controller.php b/library/Icingadb/Web/Controller.php index 913bf6e4..2cad5464 100644 --- a/library/Icingadb/Web/Controller.php +++ b/library/Icingadb/Web/Controller.php @@ -122,17 +122,19 @@ class Controller extends CompatController * This automatically shifts the view mode URL parameter from {@link $params}. * * @param PaginationControl $paginationControl - * @param LimitControl $limitControl - * @param bool $verticalPagination + * @param LimitControl $limitControl + * @param bool $verticalPagination + * @param class-string $viewModeSwitcherClass * * @return ViewModeSwitcher|GridViewModeSwitcher */ public function createViewModeSwitcher( PaginationControl $paginationControl, LimitControl $limitControl, - bool $verticalPagination = false + bool $verticalPagination = false, + string $viewModeSwitcherClass = ViewModeSwitcher::class ): ViewModeSwitcher { - $viewModeSwitcher = $this->getViewModeSwitcherInstance(); + $viewModeSwitcher = new $viewModeSwitcherClass(); $viewModeSwitcher->setIdProtector([$this->getRequest(), 'protectId']); @@ -259,17 +261,6 @@ class Controller extends CompatController return $viewModeSwitcher; } - /** - * Return an instance of the view mode switcher for the current controller, - * controllers that need special view mode switchers should override this method. - * - * @return ViewModeSwitcher - */ - protected function getViewModeSwitcherInstance(): ViewModeSwitcher - { - return new ViewModeSwitcher(); - } - /** * Process a search request *