Problem/Motivation

We have a use case where the Search Block URL is not static, and need to adapt to the current page it's placed on. It would be great to use token replacement values to assign a current page URL, which tokens can be expanded for all types of use cases.

Comments

droath created an issue. See original summary.

droath’s picture

droath’s picture

Status: Active » Needs review
phjou’s picture

Good job droath! Nice feature.

I found two things:
- The patch was crashing when the block was placed on a page that is not a node. So we need ", required = FALSE" in the contextdefinition
- Why not applying the token replacement on the input name as well, that gives more power to content editors

I will make these adjustments and merge.

phjou’s picture

  • phjou committed 867cabae on 1.0.x
    Issue #3320536 by droath, phjou: Allow search URL to support token...
phjou’s picture

Status: Needs review » Fixed
fjgarlin’s picture

This 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)

I'll open a follow up issue with all the above info.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.