Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Spider84 on
Hello.
I have a view with a filter. I ned to catch up a value from argument, convert it and pass it to view filter.
I hav created the following code.
function customcode_views_pre_view(&$view, &$display_id, &$args){
$view->display['default']->handler->options['filters']['field_raion_value']['value'] = array(
'val1' => 'val1'
);
}
The code is worked well - I have tested it with debug, but it has no effect. The filter value doesnt changed.
Drupal 7 and views 3.
Can you help me?
Comments
Have a look here. He's
Have a look here. He's fetching a value from the $_SESSION array, but it should be easy enough to adapt to your use case.
PS: btw .. you probably want to filter the View by at least it's ID .. otherwise you will apply the filter to every view which you most certainly don't want.
I like cookies!
I would try :
I would try :
In drupal 8
That helped me, I just want to add that in drupal 8 it will be :
$filters = $view->display_handler->getOption('filters');
In drupal 8
For hook_views_pre_view(&$view)
works @ricobanga
works @ricobanga
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js
Views panes
This works great on a standard Views page, but it does not seem to work on a Views pane in Panels. Any suggestions?
Same as him.
Same as him.
Not working in panels.
@ricobanga works :D
@ricobanga
works :D
You can try
You can try hook_views_default_views_alter in your custom module to change the filters of a particular view.
https://api.drupal.org/api/views/views.api.php/function/hook_views_defau...
Ex: