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:

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

Any ideas?

  • 1
    I suspect it's because you are using {gid} and not {group}.
    – Jaypan
    Feb 16, 2022 at 5:47
  • @Jaypan that was indeed the problem. I will accept your answer if you post one
    – Ronnie
    Feb 16, 2022 at 17:08
  • Done, thanks. And glad it worked out.
    – Jaypan
    Feb 17, 2022 at 6:36

1 Answer 1


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'

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.