1

I try to add a new filter criteria to my views with a custom module.

I manage to display my new filter on the filter criteria list but when I select it and go to "Add and configure filter criteria" I have an error saying:

The handler for this item is broken or missing. The following details are available:

Enabling the appropriate module may solve this issue. Otherwise, check to see if there is a module update available.

Here is my content_search.module :

function content_search_views_data_alter(&$data)
{
    $data['node']['content_search_filter'] = [
        'title' => t('Content search filter'),
        'filter' => [
            'title' => t('Content search filter'),
            'help' => 'Filters nodes on its content',
            'field' => 'nid',
            'id' => 'content_search_filter',
        ]
    ];
}

And here is my ContentSearchFilterPlugin, placed in content_search/src/Plugin/Filter/ContentSearchFilterPlugin.php

namespace Drupal\content_search\Plugin\Filter;

use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\filter\FilterPluginBase;

/**
 * Filters nodes on on their content
 *
 * @ingroup views_filter_handlers
 *
 * @ViewsFilter("content_search_filter")
 */
class ContentSearchFilterPlugin extends FilterPluginBase {
  /**
   * {@inheritdoc}
   */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view, $display, $options);
    $this->valueTitle = t('Content search filter');
  }


  public function query() {
    parent::query();
    // TODO: custom query here
  }

}

What am I missing ?

1

I think you have a problem with plugin file organization. It should be :

content_search/src/Plugin/views/filter/ContentSearchFilterPlugin.php

...instead of

content_search/src/Plugin/Filter/ContentSearchFilterPlugin.php

And the namespace for this file should be

namespace Drupal\content_search\Plugin\views\filter;

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.