public function IndexController::indexBypassEnable in Search API 8
Enables a search index without a confirmation form.
Parameters
\Drupal\search_api\IndexInterface $search_api_index: The index to be enabled.
Return value
\Symfony\Component\HttpFoundation\Response The response to send to the browser.
1 string reference to 'IndexController::indexBypassEnable'
File
- src/
Controller/ IndexController.php, line 152
Class
- IndexController
- Provides route responses for search indexes.
Namespace
Drupal\search_api\ControllerCode
public function indexBypassEnable(IndexInterface $search_api_index) {
// Enable the index.
$search_api_index
->setStatus(TRUE)
->save();
// \Drupal\search_api\Entity\Index::preSave() doesn't allow an index to be
// enabled if its server is not set or disabled.
if ($search_api_index
->status()) {
// Notify the user about the status change.
$this
->getMessenger()
->addStatus($this
->t('The search index %name has been enabled.', [
'%name' => $search_api_index
->label(),
]));
}
else {
// Notify the user that the status change did not succeed.
$this
->getMessenger()
->addWarning($this
->t('The search index %name could not be enabled. Check if its server is set and enabled.', [
'%name' => $search_api_index
->label(),
]));
}
// Redirect to the index's "View" page.
$url = $search_api_index
->toUrl('canonical');
return $this
->redirect($url
->getRouteName(), $url
->getRouteParameters());
}