public function GroupMedia::getGroupOperations in Group Media 8
Same name and namespace in other branches
- 8.2 src/Plugin/GroupContentEnabler/GroupMedia.php \Drupal\groupmedia\Plugin\GroupContentEnabler\GroupMedia::getGroupOperations()
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/ GroupMedia.php, line 42
Class
- GroupMedia
- Provides a content enabler for nodes.
Namespace
Drupal\groupmedia\Plugin\GroupContentEnablerCode
public function getGroupOperations(GroupInterface $group) {
$account = \Drupal::currentUser();
$plugin_id = $this
->getPluginId();
$type = $this
->getEntityBundle();
$operations = [];
if ($group
->hasPermission("create {$plugin_id} entity", $account)) {
$route_params = [
'group' => $group
->id(),
'plugin_id' => $plugin_id,
];
$operations["groupmedia-create-{$type}"] = [
'title' => $this
->t('Create @type', [
'@type' => $this
->getMediaBundle()
->label(),
]),
'url' => new Url('entity.group_content.create_form', $route_params),
'weight' => 30,
];
}
return $operations;
}