Problem/Motivation
#3320536: Allow search URL to support token values introduced a regression if the "node" module is not enabled. I know it's not very common on Drupal sites but totally possible.
Before the update, it all works, after the update:
The website encountered an unexpected error. Please try again later.
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "entity:node" plugin does not exist. Valid plugin IDs for Drupal\Core\TypedData\TypedDataManager are: filter_format, search_api_html, search_api_text, entity, entity:branch, entity:docblock_class_member, entity:docblock_file, entity:docblock_function, entity:docblock_namespace, entity:docblock_override, entity:docblock_reference, entity:docblock_reference_count, entity:docblock, entity:external_branch, entity:external_documentation, entity:php_branch, entity:php_documentation, entity:project, entity:block, entity:comment, entity:comment:api_comment, entity:comment_type, entity:editor, entity:facets_facet, entity:facets_facet_source, entity:field_config, entity:field_storage_config, entity:file, entity:filter_format, entity:image_style, entity:configurable_language, entity:language_content_settings, entity:menu_link_content, entity:menu_link_content:menu_link_content, entity:path_alias, entity:redirect, entity:redirect:redirect, entity:search_api_index, entity:search_api_server, entity:search_api_task, entity:social_auth, entity:action, entity:menu, entity:user_role, entity:user, entity:pathauto_pattern, entity:view, entity:date_format, entity:entity_form_display, entity:entity_form_mode, entity:entity_view_display, entity:entity_view_mode, entity:base_field_override, entity_reference, field_item:comment, field_item:file, field_item:file_uri, field_item:image, field_item:link, field_item:list_float, field_item:list_integer, field_item:list_string, field_item:path, field_item:redirect_source, field_item:text, field_item:text_long, field_item:text_with_summary, field_item:boolean, field_item:changed, field_item:created, field_item:decimal, field_item:email, field_item:entity_reference, field_item:float, field_item:integer, field_item:language, field_item:map, field_item:password, field_item:string, field_item:string_long, field_item:timestamp, field_item:uri, field_item:uuid, any, binary, boolean, datetime_iso8601, duration_iso8601, email, float, integer, list, language, language_reference, map, string, timespan, timestamp, uri in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).
Drupal\Core\Plugin\DefaultPluginManager->getDefinition('entity:node') (Line: 115)
Drupal\Core\TypedData\TypedDataManager->createDataDefinition('entity:node') (Line: 249)
Drupal\Core\Plugin\Context\ContextDefinition->getDataDefinition() (Line: 123)
Drupal\Core\Plugin\Context\Context->getContextData() (Line: 84)
Drupal\Core\Plugin\Context\Context->hasContextValue() (Line: 125)
Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping(Object, Array) (Line: 122)
Drupal\block\BlockAccessControlHandler->checkAccess(Object, 'view', Object) (Line: 105)
Running a trace, the error is in "SearchBlock.php":
#0 /var/www/html/web/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryCachedTrait.php(25): Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition(Array, 'entity:node', true)
#1 /var/www/html/web/core/lib/Drupal/Core/TypedData/TypedDataManager.php(115): Drupal\Core\Plugin\DefaultPluginManager->getDefinition('entity:node')
#2 /var/www/html/web/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php(249): Drupal\Core\TypedData\TypedDataManager->createDataDefinition('entity:node')
#3 /var/www/html/web/core/lib/Drupal/Core/Plugin/Context/Context.php(123): Drupal\Core\Plugin\Context\ContextDefinition->getDataDefinition()
#4 /var/www/html/web/core/lib/Drupal/Core/Plugin/Context/Context.php(84): Drupal\Core\Plugin\Context\Context->getContextData()
#5 /var/www/html/web/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php(125): Drupal\Core\Plugin\Context\Context->hasContextValue()
#6 /var/www/html/web/core/modules/block/src/BlockAccessControlHandler.php(122): Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping(Object(Drupal\search_api_block\Plugin\Block\SearchBlock), Array)
#7 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php(105): Drupal\block\BlockAccessControlHandler->checkAccess(Object(Drupal\block\Entity\Block), 'view', Object(Drupal\Core\Session\AccountProxy))
#8 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(314): Drupal\Core\Entity\EntityAccessControlHandler->access(Object(Drupal\block\Entity\Block), 'view', Object(Drupal\Core\Session\AccountProxy), true)
#9 /var/www/html/web/core/modules/block/src/BlockRepository.php(63): Drupal\Core\Entity\EntityBase->access('view', NULL, true)
Steps to reproduce
- Install latest supported Drupal version
- Install the module and place a block on the header.
- Uninstall the node module
Proposed resolution
Remove the dependency or check if the module is enabled before using any "node" specific notation.
Remaining tasks
Provide patch or MR.
User interface changes
API changes
Data model changes
Comments
Comment #2
fjgarlin commentedComment #3
fjgarlin commentedThe 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).
Comment #4
fjgarlin commented(Untested) maybe changing the context definitions to this
and changing the code below where "node" is used might do the trick?
Comment #5
phjouNice 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.
Comment #7
fjgarlin commentedI'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.
Comment #8
phjouSorry 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:
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 not even 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!
Comment #11
phjouComment #12
phjouI 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.
Comment #13
fjgarlin commentedThank you as well for the prompt replies, fixes, and release.