You are here

public function GroupContentMenu::getGroupOperations in Group Content Menu 8

Provides a list of operations for a group.

These operations can be implemented in numerous ways by extending modules. Out of the box, Group provides a block that shows the available operations to a user visiting a route with a group in its URL.

Do not forget to specify cacheable metadata if you need to. This can be done in ::getGroupOperationsCacheableMetadata().

Parameters

\Drupal\group\Entity\GroupInterface $group: The group to generate the operations for.

Return value

array An associative array of operation links to show when in a group context, keyed by operation name, containing the following key-value pairs:

  • title: The localized title of the operation.
  • url: An instance of \Drupal\Core\Url for the operation URL.
  • weight: The weight of the operation.

Overrides GroupContentEnablerBase::getGroupOperations

See also

::getGroupOperationsCacheableMetadata()

File

src/Plugin/GroupContentEnabler/GroupContentMenu.php, line 43

Class

GroupContentMenu
Provides a content enabler for group menus.

Namespace

Drupal\group_content_menu\Plugin\GroupContentEnabler

Code

public function getGroupOperations(GroupInterface $group) {
  $account = \Drupal::currentUser();
  $operations = [];
  $url = Url::fromRoute('entity.group_content_menu.collection', [
    'group' => $group
      ->id(),
  ]);
  if ($url
    ->access($account)) {
    $operations['group-content-menu-collection'] = [
      'title' => $this
        ->t('Edit group menus'),
      'url' => $url,
      'weight' => 100,
    ];
  }
  return $operations;
}