0

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

3
  • 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?
    – No Sssweat
    Mar 6, 2020 at 9:24
  • Yes i want to pass that session variable value as a contextual filter value. Thanks for your reply
    – Dev-Kaleem
    Mar 6, 2020 at 12:37
  • 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.
    – Kevin
    Mar 6, 2020 at 20:05

1 Answer 1

0

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
  }
}
1
  • @Kevin Thanks a lot for your response. I try it now.
    – Dev-Kaleem
    Mar 9, 2020 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.