Hello,

I have created a view that list all the group content of a group passed in the path :
/group/%group/documents-internes.

I cannot set the menu item as a normal menu item directly in views because of the %group.
So I'd like to create a menu custom link that take the current contextual group Id and pass it to my view.
in my links.menu.yml :

dash.docs:
  title: 'docs'
  class: Drupal\dashbd\Plugin\Menu\GroupLink
  route_name: view.tableau_documents_par_territoire.page_3
  parent: tools
  weight: 100
  route_parameters: { group: '1' }

I've tried with a lot of things but I have not found yet.
I tried with a class that can change the route_parameters but I have not found to to find the group id :

namespace Drupal\dashbd\Plugin\Menu;

use Drupal\Core\Menu\MenuLinkDefault;
use Drupal\Core\Menu\StaticMenuLinkOverridesInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\group\Entity\GroupInterface;
use Drupal\group\Entity\GroupContent;
use Drupal\group\Context\GroupRouteContextTrait;

/**
 * Represents a menu link for a user profile edition.
 */
class GroupLink extends MenuLinkDefault {

 use GroupRouteContextTrait;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, StaticMenuLinkOverridesInterface $static_override ) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $static_override);
    $group = $this->getGroupFromRoute();
    kint($group->id);
  }


public function getRouteParameters() {
    // If the user is not Anonymous.
      // return the godd current grop ID.
      return ['group' => '1'];
  }
}

So is there a way to do properly just like the links in the operation group ?

Thanks,
Didier

Comments

did1979 created an issue. See original summary.

markconroy’s picture

Hi Didier,

Just wanted to check-in here to see if you ever got this resolved?

markconroy’s picture

I think I have it working now.

In module_name.links.yml I have this:

module_name.registrations:
  title: 'View Registrations'
  description: 'View all registrations by the current company'
  menu_name: 'product-registration'
  route_name: view.company_registrations.page_1
  class: Drupal\module_name\Plugin\Menu\RegistrationsLink

and then in src/Plugin/Menu/RegistrationsLink.php I have this:

<?php

namespace Drupal\module_name\Plugin\Menu;

use Drupal\Core\Menu\MenuLinkDefault;
use Drupal\group\Context\GroupRouteContextTrait;

/**
 * Represents a menu link for a ...
 */
class RegistrationsLink extends MenuLinkDefault {

 use GroupRouteContextTrait;

public function getRouteParameters() {
  $group = $this->getGroupFromRoute();
    $group_id = $group->id->value;
      return ['group' => $group_id];
  }
}
markconroy’s picture

Priority: Major » Normal
Status: Active » Needs review

Downgrading this from "Major" to "Normal".

To maintainers: I'm marking this "Needs review". I reckon it should be marked "Closed: works as designed".

matslats’s picture

Component: Group (group) » Code

I'm working with the module now and seems to me that custom node is needed in order to make menu links that reference the .
Seems pretty important to me.
I don't know how I would go about it.
How about a new menu called 'group' which provides links to ordinary group members to :
- view members
- view content (by type)
- add content (by type)
- manage membership
The menu would be defined as a config item in config/install
The menu links, each pointing to its own class would be defined in the group.links.menu.yml
Would this not be a great addition to the module?

matslats’s picture

Update:
I also found the group content menu but it seemed over complicated and i couldn't make it work. In any case I'm not looking for a menu with links to content but links to actions.
So then I found the group operations block which doesn't work as expected but might be good enough.
I also researched into how one might make a token that could be put into a menu link path like
/group//members
where the menu item would only show in a group context, and the would be replaced by the current group ID OR the link would redirect to the current group. However I couldn't work out how to do this.