0

How to add a custom views filter handler for a specific field? answers on how to add a filter to a base field.

I'm looking to add a filter to a non base field. (The field name is contact).

Here's what I have so far:

/**
 * Implements hook_views_data_alter().
 */
function custom_contact_views_data_alter(array &$data) {
  $data['node__contact']['active_contact'] = [
    'title' => t('Active contact filter'),
    'filter' => [
      'title' => t('Active contact filter'),
      'help' => 'Filters node on active contact',
      'field' => 'contact_target_id',
      'id' => 'active_contact',
    ],
  ];
}

It is added, but it complains about group missing in the Views UI Error: missing group

How should the views data be defined when adding a custom filter to a non-base field?

0

You get the error Error: missing group.

You should be able to fix it by adding the group property, like this:

$data['node__contact']['active_contact'] = [
  'title' => t('Active contact filter'),
  'group' => t('Contact'), // Add this line.
  '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.