I am new to Drupal 8. I get group_id in session variable just like that $_SESSION['groupbysession']['group_id'] = $path[2];
. now i want to get that session variable in view Contextual filters.I have no idea how to do this. I also use view extra module for this but doesn't work for me.Thanks in advance
1 Answer
You'll need to create a custom module and pass the value Group ID value using hook_views_pre_view
Example:
/*
* Implements hook_views_pre_view()
*/
function mymodule_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
// Modify contextual filters for my_special_view.
if ($view->id() == 'my_special_view') { // target a specific view
// if you want you could make it even more specific by adding ex: "&& $display_id == 'block_1')"
$group_id = $_SESSION['groupbysession']['group_id'];
$args[0] = $group_id; // set argument
}
}
now i want to get that session variable in view Contextual filters
you mean you want to pass that session variable value as a contextual filter value?I also use view extra module for this but doesn't work for me.
it would seem more pertinent to report "what doesn't work" to that module issue queue so they can fix a bug if in fact that is what is occurring.