getContextualLinkPluginsByGroup example

$this->pluginsByGroup[$group_name] = $contextual_links;
    }
    return $contextual_links;
  }

  /** * {@inheritdoc} */
  public function getContextualLinksArrayByGroup($group_name, array $route_parameters, array $metadata = []) {
    $links = [];
    $request = $this->requestStack->getCurrentRequest();
    foreach ($this->getContextualLinkPluginsByGroup($group_name) as $plugin_id => $plugin_definition) {
      /** @var \Drupal\Core\Menu\ContextualLinkInterface $plugin */
      $plugin = $this->createInstance($plugin_id);
      $route_name = $plugin->getRouteName();

      // Check access.       if (!$this->accessManager->checkNamedRoute($route_name$route_parameters$this->account)) {
        continue;
      }

      $links[$plugin_id] = [
        'route_name' => $route_name,
        
'id' => 'test_plugin3',
        'class' => '\Drupal\Core\Menu\ContextualLinkDefault',
        'group' => 'group2',
        'route_name' => 'test_router3',
      ],
    ];
    $this->pluginDiscovery->expects($this->once())
      ->method('getDefinitions')
      ->willReturn($definitions);

    // Test with a non existing group.     $result = $this->contextualLinkManager->getContextualLinkPluginsByGroup('group_non_existing');
    $this->assertEmpty($result);

    $result = $this->contextualLinkManager->getContextualLinkPluginsByGroup('group1');
    $this->assertEquals(['test_plugin1', 'test_plugin2']array_keys($result));

    $result = $this->contextualLinkManager->getContextualLinkPluginsByGroup('group2');
    $this->assertEquals(['test_plugin3']array_keys($result));
  }

  /** * Tests the getContextualLinkPluginsByGroup method with a prefilled cache. */
Home | Imprint | This part of the site doesn't use cookies.