While developing a site using search api, search api ranges in combination with entity translation we found that the module causes a fatal error expecting a valid class or name.
Because we are using entity translation the function search_api_ranges_minmax expects $index->type to be a valid entity type, when using entity translation the returned value is search_api_et_node and the entity id is prefixed EG en_2404 instead of 2404.
We solved this issue by changing the code around line 185 in search_api_ranges.module to:
$result_ids = array();
foreach ($results['results'] as $result) {
if($index->item_type == 'search_api_et_node') {
$result_ids[] = is_numeric($result['id']) ? $result['id'] : substr($result['id'], 3);
}
else {
$result_ids[] = $result['id'];
}
}
if($index->item_type == 'search_api_et_node') {
$entities = entity_load('node', $result_ids);
} else {
$entities = entity_load($index->item_type, $result_ids);
}
If the type is search_api_et_node we remove the prefix (substr starting from 3) and load the content by hardcoding the type to node to load the entities.
Beware: this solution works for this project but might not work if your index also contains language neutral content or other types of entities.
Comment | File | Size | Author |
---|---|---|---|
#5 | search_api_ranges-search_api_et_support-2321269-5.patch | 1.05 KB | drclaw |
Comments
Comment #1
maciej.zgadzaj CreditAttribution: maciej.zgadzaj commentedThe module shouldn't assume that
item_type
is valid entity type. Instead, it should use relevant method provided for this exact purposeSearchApiDataSourceControllerInterface::getEntityType()
.Patch attached.
Comment #2
Martin. CreditAttribution: Martin. commentedThis patch only fixes the fatal error. The filter itself is not working. Did you actually got it working ? Please share the solution if you did.
Might be related with https://www.drupal.org/node/2321269
Comment #3
detroz CreditAttribution: detroz commentedHi,
I propose this alteration of the function search_api_ranges_minmax($variables, $order = 'ASC') on the file "search_api_ranges.module" :
Comment #4
Aambro CreditAttribution: Aambro as a volunteer commentedI couldn't apply the patch as the code was slightlly different:
So I just changed the
item_type
togetEntityType()
Final code, that works for me:
Comment #5
drclaw CreditAttribution: drclaw at Fuse Interactive commentedHere's a patch that adds support for any entity type that search_api_et may have multilingual indexes for.
Note that @Aambro's code in comment #4 is for the 7.x-1.5 version of the module, whereas the patch is for the development branch.
Comment #6
gonssalI confirm the patch in #5 works. Thx drclaw and the rest.
Maybe time to commit and release as new version, so I can upgrade commerce kickstart without having to download the dev version and applying the patch everytime? ;)
Comment #8
Scott Robertson CreditAttribution: Scott Robertson commentedComment #10
gonssalIs there anything blocking a new release so we can get this in a new stable version?