Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
It is currently only possible to create views based on the base table of the entity. It would be great to allow any views table for a particular entity type to provide selection views, such as Search API which can allow you to do a lot more advanced searching.
The piece of code that currently stops it is:
plugins/selection/EntityReference_SelectionHandler_Views.class.php::28
$entity_info = entity_get_info($field['settings']['target_type']);
$options = array();
foreach ($displays as $data) {
list($view, $display_id) = $data;
if ($view->base_table == $entity_info['base table']) {
$options[$view->name . ':' . $display_id] = $view->name . ' - ' . $view->display[$display_id]->display_title;
}
This explicitly enforces only the base table, excluding all other possibilities.
Proposed resolution
Check the table's definition to see if it is has an entity type. This would allow other modules to provide tables that are compatible.
Comment | File | Size | Author |
---|---|---|---|
#2 | d7_entityreference_searchapi_selection.patch | 5.62 KB | fago |
#1 | 2098093-1-allow_non_base_table_views_tables.patch | 1.12 KB | andrewbelcher |
Comments
Comment #1
andrewbelcher CreditAttribution: andrewbelcher commentedHere is a patch that implements the proposed resolution by checking whether the table is of the particular entity type:
Comment #1.0
andrewbelcher CreditAttribution: andrewbelcher commentedAdd a file/line reference for the code quote
Comment #2
fagoUnfortunately the patch is not everything that's required to support search api based views.
Howsoever, attached is a patch which adds search api support, i.e. talks the search api query plugin. I've tested it with solr only, for search-api db backend support (or others) the wildcard character would have to be replaced accordingly (see @todo). (It's a pity search api has no support for handling wildcard queries itself)
The code would probably better live in a separate search-api specific sub-class, but it doesn't look like there is a simple way to switch display handler classes per query backend.
Comment #3
andrewbelcher CreditAttribution: andrewbelcher commentedI've a feeling this isn't necessary, but it's been a while since I looked at it.
Either way, I think any Search API specific code should probably go in Search API? The patch I posted allows other modules to implement what they need. For example, if more is necessary for Search API integration, it could extend the views class to do the additional work.
The better option would be to make sure that the use of views us back-end agnostic. #1989952: Allow match to be passed to exposed filters is a start on that by using exposed filters rather than the somewhat hacky way it currently works.
I'll try an take a look and see where I got up to, but I think the patch from #1 is the answer to this issue...
Comment #4
jason.fisher CreditAttribution: jason.fisher commentedI am currently struggling with the same issue. I have "Indexed Node: Related (exposed)" for my field_related_ref entity reference field with Search API Solr and Views and cannot get it to appear as anything other than a text input.