Hi,
I'm trying to build a new facet, or modify an existing one to include the items from others.
What I'm trying to achieve is have a facet block that have a list of content types, the existing 'type' facet, plus the items from one or more existing facets, as 'field_news_type', that have a category in a content type defined by an integer list.
My aproach, that could not be the best, is implement hook_facet_items_alter(&$build, &$settings) from the facetapi_bonus module.
So, I am trying to include new items to the $build array.
Is there a way to programmatically call the query that get the items from a specific facet and include the items from another?.
I'm using facetapi-1.5, search_api-1.13, search_api_solr-1.5.
I'm trying to get a list of built items, form this method FacetapiFacet $facet->getBuild(), but I can't instanciate the object properly.
What I'm doing in my module is:
function mymodule_facet_items_alter(&$build, &$settings) {
//I need to add more items to the $build array
if ($settings->facet == "type") {
$adapter = facetapi_adapter_load('search_api@devel_nodes_index');
$facets = new FacetapiFacet($adapter, facetapi_facet_load('field_news_type','search_api@devel_nodes_index'));
$build_list = $facets->getBuild(); // I spect to get a list of items
}
}
I guess, I'm missing steps and I manually should call another methods to properly setup the adapter and facet objects.
Is there another recommended aproach to do this?
Comments
Comment #1
betoscopioComment #2
Shuairan CreditAttribution: Shuairan commentedhad the same problem, combining values from two different facets. Maybe this code will help you:
Comment #3
betoscopioHey Shuairan, thank you very much, using your code worked for me. I wasn't aware about the FacetapiFacetProcessor object.
Just curios to know, how did you implemented this? in some particular hook?, or just like me using hook_facet_items_alter from the facetapi_bonus module.
Greetings,
Beto.
Comment #4
Shuairan CreditAttribution: Shuairan commentedbtw: "build" is a protected property. $processor->getBuild() instead of $processor->build would be the right thing in the comment for accessing the values without building the real facet with filters etc.
I am using this as an own FacetapiFilter to build a custom-region-based hierarchy for countries. This is nearly the same as your hook_facet_items_alter which comes from facetapi_bonus and works also with FacetapiFilter (FacetapiFilterRewriteItems).
For my case implementing the hook_facetapi_facet_info_alter and changing/defining the 'hierarchy callback' to do this restructuring for the specific field would even be a litte bit nicer... but in all non-hierarchy cases using the hook_facet_items_alter will be fine.
Comment #5
betoscopioThanks Shuairan for the explanation, was very clear to me.
Comment #6
DamienMcKennaThis might be useful as a documentation improvement?
Comment #7
jstraney CreditAttribution: jstraney commentedThank you. I also have run into this problem and this was instrumental to solving it. Would be very nice to see something this specific in the docs.