You have to alter the route defined by the search module.
In order to do so:
- Define in your
mymodule.services.yml
file following:
services:
mymodule.route_subscriber:
class: Drupal\mymodule\Routing\RouteSubscriber
tags:
- { name: event_subscriber }
- Create a class that extends the
RouteSubscriberBase
class on /mymodule/src/Routing/RouteSubscriber.php as following:
<?php
/**
* @file
* Contains \Drupal\mymodule\Routing\RouteSubscriber.
*/
namespace Drupal\mymodule\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
/**
* Listens to the dynamic route events.
*/
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection) {
// Replace dynamically created "search.view_node_search" route's Controller
// with our own.
if ($route = $collection->get('search.view_node_search')) {
$route->setDefault('_controller', '\Drupal\mymodule\Controller\MyModuleSearchController::view');
}
}
}
- Finally, the controller itself located on /mymodule/src/Controller/MyModuleSearchController.php
<?php
namespace Drupal\mymodule\Controller;
use Drupal\search\SearchPageInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\search\Controller\SearchController;
/**
* Override the Route controller for search.
*/
class MyModuleSearchController extends SearchController {
/**
* {@inheritdoc}
*/
public function view(Request $request, SearchPageInterface $entity) {
$build = parent::view($request, $entity);
// Unset the Result title.
if (isset($build['search_results_title'])) {
unset($build['search_results_title']);
}
return $build;
}
}