- Issue created by @Brolad
- @brolad opened merge request.
- Status changed to Needs review
over 1 year ago 3:40pm 20 March 2023
The passed value for 'views_arguments' of the 'autocomplete_route_parameters' property doesn't execute view with these arguments.
Use an example from the module's README file:
1) Create a view via Structure- > views -> Add new view.
2) Alter a field via hook_form_alter in .module.
or
2) Create an custom field with autocompletion.
// To make it autocomplete, here is an example.
$form['example_autocomplete'] = [
'#type' => 'textfield',
'#autocomplete_route_name' => 'views_autocomplete_api',
'#autocomplete_route_parameters' => [
'view_name' => 'my_view_1',
'display_id' => 'default',
'views_arguments' => 'args1',
],
];
Try to find data using autocomplete based on the views contextual filter. The filter is ignored.
\Drupal\views_autocomplete_api\Controller\ViewsAutocompleteApiController::getViewsDataJson() executing for views_autocomplete_api route and there we have a code:
$args_views = $this->viewsAutocompleteManager->prepareArgumentViews(
$views_arguments,
count($view_name)
);
where $views_arguments coming from 'views_arguments' value of a property "autocomplete_route_parameters" that we rewrited before. So, that means we'll pass a value "args1" to prepareArgumentViews() method. Inside of this method we have the next code:
public function prepareArgumentViews($views_arguments, $count_view) {
// Prepare arguments.
$args_views = [];
if (!empty($views_arguments)) {
return $args_views;
}
...
There we have a condition that always returns an empty array when we want to pass a views argument. The result of that is not passed views arguments for views execute.
I propose to update condition to return empty array only when $views_arguments is empty.
Needs review
2.1
Code