0

This question already has an answer here:

Let's say in /var/www/drupal8/core/modules/search/src/Controller/SearchController.php below is the snippet

class SearchController extends ControllerBase {
     ...
     ...

  public function view(Request $request, SearchPageInterface $entity) {

       ...
       ...
      if (count($results)) {
         $build['search_results_title'] = array(
        '#markup' => '<h2>' . $this->t('Search results') . '</h2>',
       );
     }
      ...
   } 
}

So in the above snippet I want to change the text Search results in line

'#markup' => '<h2>' . $this->t('Search results') . '</h2>',

I want to override above view method extending class SearchController in my custom module.

What are the exact steps to do this?

I am using drupal 8.2.1.

marked as duplicate by Yusef Mohamadi, kiamlaluno Mar 29 '17 at 12:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You'll need to alter the route as described here, probably using $route->setDefaults() to replace the _controller with your own – Clive Mar 29 '17 at 11:59
  • If you're using Search API, you could just create your own view, too. – Kevin Mar 29 '17 at 12:06

Browse other questions tagged or ask your own question.