function SearchController::performOperation

Same name in other branches
  1. 9 core/modules/search/src/Controller/SearchController.php \Drupal\search\Controller\SearchController::performOperation()
  2. 8.9.x core/modules/search/src/Controller/SearchController.php \Drupal\search\Controller\SearchController::performOperation()
  3. 11.x core/modules/search/src/Controller/SearchController.php \Drupal\search\Controller\SearchController::performOperation()

Performs an operation on the search page entity.

Parameters

\Drupal\search\SearchPageInterface $search_page: The search page entity.

string $op: The operation to perform, usually 'enable' or 'disable'.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse A redirect back to the search settings page.

1 string reference to 'SearchController::performOperation'
search.routing.yml in core/modules/search/search.routing.yml
core/modules/search/search.routing.yml

File

core/modules/search/src/Controller/SearchController.php, line 196

Class

SearchController
Route controller for search.

Namespace

Drupal\search\Controller

Code

public function performOperation(SearchPageInterface $search_page, $op) {
    $search_page->{$op}()
        ->save();
    if ($op == 'enable') {
        $this->messenger()
            ->addStatus($this->t('The %label search page has been enabled.', [
            '%label' => $search_page->label(),
        ]));
    }
    elseif ($op == 'disable') {
        $this->messenger()
            ->addStatus($this->t('The %label search page has been disabled.', [
            '%label' => $search_page->label(),
        ]));
    }
    $url = $search_page->toUrl('collection');
    return $this->redirect($url->getRouteName(), $url->getRouteParameters(), $url->getOptions());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.