Score:0

How to pass group context to custom form page using group module

in flag

I have a custom block that is displayed within each group on every page. The block visibility is set to /league/*

The custom block shows up fine for /league/{gid}, /league/{gid}/members, /league/{gid}/edit, /league/{gid}/invitations etc.

I created a custom form with a route of /league/{gid}/segments, but my block is not rendering correctly on that page because of this line in my block:

if (($group = $this->getContextValue('group')) && $group->id()) {

I got that line from the group module /src/Plugin/Block/GroupOperationsBlock.php

$this->getContextValue('group')) is not defined.

How can I pass the group context to that form page? I tried adding the options of group to the route like this, but no luck:

mymodule.segments:
  path: '/league/{gid}/segments'
  defaults:
    _title: 'Segments'
    _form: 'Drupal\mymodule\Form\SegmentsForm'
  requirements:
    _permission: 'authenticated'
  options:
    parameters:
      group:
        type: 'entity:group'

Any ideas?

Jaypan avatar
de flag
I suspect it's because you are using `{gid}` and not `{group}`.
in flag
@Jaypan that was indeed the problem. I will accept your answer if you post one
Jaypan avatar
de flag
Done, thanks. And glad it worked out.
Score:1
de flag

In order for the Group to be part of the page context, it needs to be named {group} in your path. So you will need to change this:

path: '/league/{gid}/segments'

To this:

path: '/league/{group}/segments'
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.