public function Search404Controller::search404CustomErrorMessage in Search 404 8
Same name and namespace in other branches
- 2.x src/Controller/Search404Controller.php \Drupal\search404\Controller\Search404Controller::search404CustomErrorMessage()
Displays an error message of page not found.
Parameters
string $keys: Keywords to display along with the error message.
1 call to Search404Controller::search404CustomErrorMessage()
- Search404Controller::search404Page in src/
Controller/ Search404Controller.php
File
- src/
Controller/ Search404Controller.php, line 482
Class
- Search404Controller
- Route controller for search.
Namespace
Drupal\search404\ControllerCode
public function search404CustomErrorMessage($keys) {
$error_message = '';
$disable_error = \Drupal::config('search404.settings')
->get('search404_disable_error_message');
if ($disable_error) {
return;
}
if ($custom_error_message = \Drupal::config('search404.settings')
->get('search404_custom_error_message')) {
if (empty($keys)) {
$error_message = str_replace('@keys', 'Invalid keys used', $custom_error_message);
}
else {
$error_message = str_replace('@keys', $keys, $custom_error_message);
}
}
else {
// Invalid keys used, actually this happens
// when no keys are populated to search with custom path.
if (empty($keys)) {
$error_message = $this
->t('The page you requested does not exist. Invalid keywords used.');
}
else {
$error_message = $this
->t('The page you requested does not exist. For your convenience, a search was performed using the query %keys.', [
'%keys' => Html::escape($keys),
]);
}
}
if (!empty($error_message)) {
$this->messenger
->addError($error_message);
}
}