Considering Drupal\search_api\Plugin\views\query\SearchApiQuery class, I want to override shouldAbort() method there.

I have tried to create a new plugin class in my custom mod:

namespace Drupal\my_mod\Plugin\views\query;

use Drupal\search_api\Plugin\views\query\SearchApiQuery;

 * Defines a Views query class for searching on Search API indexes.
 * @ViewsQuery(
 *   id = "search_api_query",
 *   title = @Translation("Search API Query"),
 *   help = @Translation("The query will be generated and run using the Search API.")
 * )
class MymodSearchApiQuery extends SearchApiQuery {

   * @inheritdoc
  public function shouldAbort() {
    //do something fancy

But it seems to not work. How can I do it properly?


As per the suggestion by @googletorp, you should use hook_views_plugins_query_alter(). You simply update the plugin class with your own that overrides it.

function my_mod_views_plugins_query_alter(array &$plugins) {
  $plugins['search_api_query']['class'] = 'Drupal\my_mod\Plugin\views\query\MymodSearchApiQuery';

What you want to do, is to make views use your class instead of the the one solr module provides. Defining your own plugin wont help.

Instead you can use hook_views_plugins_query_alter to specify the plugin class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.