- Issue created by @fjgarlin
- 🇪🇸Spain fjgarlin
The issue that caused it needed context definitions per page, not per node, so perhaps the approach can be changed to check the current page instead of nodes.
Not sure how to do it just thinking out loud.
Just for context on my case: we will be using this module in the new D9+ version of api.drupal.org, where the "node" module is not enabled for different reasons (mostly performance and because it's really not needed).
- 🇪🇸Spain fjgarlin
(Untested) maybe changing the context definitions to this
context_definitions = { * "entity" = @ContextDefinition("entity", required = FALSE, label=@Translation("Entity")) * }
and changing the code below where "node" is used might do the trick?
- 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺
Nice catch! Thanks.
That's a good point, not sure yet what is the best solution.
What I am thinking, is maybe check if there is a hook to alter the context definition. If there is, we can add this node entity context in a hook where we would test if the node module is enabled first.
- @fjgarlin opened merge request.
- Status changed to Needs review
almost 2 years ago 11:15am 9 February 2023 - 🇪🇸Spain fjgarlin
I've made the above changes https://git.drupalcode.org/project/search_api_block/-/merge_requests/6 and tested on my project and I'm no longer getting the error.
I can also see more generic tokens available in the configuration screen, which I guess it's not a bad thing. See here:
It'd be great if you could test and validate further the changes in a site with "node" module enabled.
- 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺
Sorry for the delay, I finally had some time this weekend to have a look.
So I like the modification you made, it gives even more power (replacement for any type of entity) but it doesn't work for me as it is, it needs to be the entity type Id instead of 'entity'.
I just kept your changes and changed the value like this:$entity_value = $entity->getContextValue(); $context[$entity_value->getEntityTypeId()] = $entity_value;
After that change, it has been working perfectly.
The only issue I see is that we lose the context for the people who already used that new feature and configured their block, but it is 2 weeks old I'll just put a note into the new release to warn those possible people who already started to use that recent token feature.
Thank you so much for your help!
- Status changed to Fixed
almost 2 years ago 9:49am 20 February 2023 - 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺
I added a note in the release: https://www.drupal.org/project/search_api_block/releases/1.1.5 →
So I think we're good, don't hesitate to let me know if anything is wrong, and thanks again.
- 🇪🇸Spain fjgarlin
Thank you as well for the prompt replies, fixes, and release.