Problem/Motivation
On Drupal 11, visiting the autocomplete route (/search_api_autocomplete/{search_api_autocomplete_search}) throws a fatal error:
RuntimeException: Callable "Drupal\search_api_autocomplete\Utility\AutocompleteHelper::access" requires a value for the "$search_api_autocomplete_search" argument. in Drupal\Component\Utility\ArgumentsResolver->handleUnresolvedArgument()
The cause is that the search_api_autocomplete.autocomplete route does not declare an explicit options.parameters entry for the {search_api_autocomplete_search} parameter. In Drupal 11, EntityConverter::applies() only upcasts a route parameter when the route explicitly declares type: entity:entity_type_id in options.parameters. Without this declaration, the parameter is never converted from a raw string to a SearchInterface entity object. When AutocompleteHelper::access() is invoked as an access checker, ArgumentsResolver cannot satisfy its SearchInterface $search_api_autocomplete_search argument and throws a
RuntimeException.
Steps to reproduce
- Install
search_api_autocomplete1.x on Drupal 11. - Create and enable a Search API index with an autocomplete search entity.
- Make a request to
/search_api_autocomplete/{search_id}?q=test. - Observe the fatal
RuntimeExceptionfromArgumentsResolver.
Proposed resolution
Add an explicit options.parameters declaration to the search_api_autocomplete.autocomplete route in search_api_autocomplete.routing.yml so that Drupal's EntityConverter knows to upcast the route parameter to a SearchInterface
entity:
search_api_autocomplete.autocomplete:
path: /search_api_autocomplete/{search_api_autocomplete_search}
defaults:
_controller: \Drupal\search_api_autocomplete\Controller\AutocompleteController::autocomplete
requirements:
_search_api_autocomplete: 'TRUE'
options:
parameters:
search_api_autocomplete_search:
type: entity:search_api_autocomplete_search
Issue fork search_api_autocomplete-3594155
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3594155-route-parameter-needs
changes, plain diff MR !59
Comments
Comment #3
eduardo morales albertiReady to review
Comment #4
eduardo morales albertiComment #5
eduardo morales albertiThe errors come from a deployment, on a route rebuilding, so it can be ignored, because Drupal already detects the type.