0

I have a custom block with some values I can access in twig template of that block. Let's say variable product_type and in same twig file I'm adding another view block like

{{ drupal_block('views_block:my-view-block_1', {product_type: 'clothes'}) }}

and for that block's hook

function myModule_views_pre_view(&$view, &$display_id, &$args){
// I want that "product_type" variable here in this hook
// because I want to add a filter here like this:
$view->display_handler->display['display_options']['filters']['field_product_type_target_id']['default_value'] = $product_type;
}

Above hook is being invoked but I cannot get product_type in hook function. I'm not sure if that is the correct way to do it but I really need to pass that value from first block to second block and use that value in second block to filter out results. It's been 2 days I'm trying to figure this out. Any help would be highly appreciated :)

Thanks & Regards.

Asad ullah
  • 620
  • 2
  • 9
  • 26

1 Answers1

0

The second parameter you pass to drupal_block() is block configuration, so you won't be able to get it in the hook_views_pre_view().

Use drupal_view() instead, you will get product_type in $args:

{{ drupal_view(<view_id>, <display_id>, {product_type: 'clothes'}) }}
Kien Nguyen
  • 2,616
  • 2
  • 7
  • 24