Is there a way to check if certain conditions on a facet are met and only then display a certain custom widget? If the specified conditions are not met, the widget becomes unavailable?
This would be similar to how the processors in SearchAPI work. Example:
/**
* Can only be enabled for an index that indexes the content bundle entity.
*
* {@inheritdoc}
*/
public static function supportsIndex(IndexInterface $index) {
foreach ($index->getDatasources() as $datasource) {
if ($datasource->getEntityTypeId() == 'node') {
return TRUE;
}
}
return FALSE;
}
Is there any way to do something similar with Facet Widgets and Processors?
Comments
Comment #2
borisson_We have something almost similar with \Drupal\facets\Widget\WidgetPluginInterface::isPropertyRequired, but it's not the exact same thing.
Comment #3
dakku commentedHi Borison,
I checked isPropertyRequired, I agree it is similar but what I am looking for is something like:
- user chooses a specific field for Facet:
Glossary Index field: This field contains the Glossary (A, B, C) etc value for a specific node.
- If the user chose the glossary field, Glossary widget should become available (depending on the field criteria)
- processors should follow similar logic.
I am trying to refactor my https://www.drupal.org/project/search_api_glossary module to make it work with latest version of facets, You can check my code here:
https://github.com/dakkusingh/drupalglossaryazsearch/blob/8.x-3.x/src/Pl...
and here
https://github.com/dakkusingh/drupalglossaryazsearch/blob/8.x-3.x/src/Gl...
Any thoughts on how best to implement a field dependency check for Widgets and Processors?
Comment #4
dakku commentedI see one quick option, not sure if this is in the correct direction:
I implement a custom Facet Widget Form validator
- get facet $facet->getFieldIdentifier();
-- check if the field chosen is glossary field
-- check if glossary widget is enabled
-- if field is not glossary and widget is glossary
-- throw a validate error, user can either change the widget or change the field.
Comment #5
borisson_I agree that should provide a method to do this, that makes sense to do.
I suggest something like this:
Comment #6
dakku commentedHi Borison,
Thank you for your reply.
I am happy to give it a try to implement what you mentioned above, however I have no idea how the allowedDataType method would then change visibility of the widget upstream.
Can you give me some pointers and I can try to code it and create a patch for review?
Comment #7
borisson_Not sure how to do it yet either. My suggestion in #5 can be forgotten for now.
Comment #8
borisson_How about this implementation?
Comment #9
borisson_Tagging with vienna's tag.
Comment #11
borisson_Should fix the page + also adds docs.
Comment #12
dakku commentedThank you sir Borisson. Sounds like Vienna was quite productive session. I will try it out and feedback.
Comment #13
borisson_Now with tests!
Comment #14
strykaizerLooks good
Comment #15
borisson_