Add an entity argument handler

Created on 8 December 2021, about 3 years ago
Updated 14 September 2024, 3 months ago

Problem/Motivation

On one of my projects I need to add filtering by node reference fields. After research I don't found views handlers who can do that.

Steps to reproduce

  • Create search api index, add node entities in datasources list (I used Solr as backend for index)
  • Add node reference field to index (integer type)
  • In views try to add exposed filter by this field. It will use "search_api_numeric" plugin and you will be able just to enter nid manually and not use some kind of dropdown widget

Proposed resolution

I created patch with filter and argument plugins to filter node reference fields.
But in global scope we need to think about how we can(or not) create something like universal handler for all available entity types or just create some kind of abstract class for entity reference filter plugins, and then everyone will easily can extend this class for own purposes.

Remaining tasks

  • Test patch and commit it, as on my opinion that's a really common problem which not resolved yet.
  • Write tests?
  • Get feedback from maintainer/community about proposed resolution.
✨ Feature request
Status

Needs work

Version

1.0

Component

Views integration

Created by

πŸ‡ΊπŸ‡¦Ukraine id.conky UA, Lutsk

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom kenorb

    This patch generates the error in the newer version of Search API:

    php Error Drupal\Component\Plugin\Exception\PluginException: Plugin (search_api_node) instance class "Drupal\search_api\Plugin\views\filter\SearchApiNode" does not exist. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (line 97 of web/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php).

    I think it needs to register its new class in search_api.services.yml

  • πŸ‡ΊπŸ‡ΈUnited States joshuami Portland, OR

    Now that Fix label token replacement for views entity reference arguments πŸ› Fix label token replacement for views entity reference arguments Fixed has landed in 10.3, this should probably be rewritten as a /src/Plugin/views/argument/SearchApiEntity.php handler instead of targeting just node. That might allow for the removal of /src/Plugin/views/argument/SearchApiTerm.

    Adding a related issue that was probably incorrectly attributed to subpathauto: Views contextual filter replacement pattern doesn't use referenced entity's title available πŸ› Views contextual filter replacement pattern doesn't use referenced entity's title available Postponed .

  • πŸ‡ΊπŸ‡ΈUnited States joshuami Portland, OR
  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    @joshuami: I agree, that would make sense. Thanks for bringing it up!
    However, note that we still want to support Drupal 10.2 until its EOL in December, so any MR depending on this change (unless it makes it into Drupal 10.2, too) couldn’t be merged until then. Still probably the way to go.

Production build 0.71.5 2024