function groupmedia_entity_operation in Group Media 8.2
Implements hook_entity_operation().
File
- ./
groupmedia.module, line 100 - Allows to associate media content to group.
Code
function groupmedia_entity_operation(EntityInterface $entity) {
$operations = [];
if ($entity
->getEntityTypeId() == 'group' && \Drupal::moduleHandler()
->moduleExists('views')) {
/** @var \Drupal\group\Entity\GroupInterface $entity */
if (!$entity
->hasPermission('access group_media overview', \Drupal::currentUser())) {
// Exit early without checking group content plugins.
return $operations;
}
// Get the list of the group_content plugins enabled for this group type.
$plugin_ids = $entity
->getGroupType()
->getInstalledContentPlugins()
->getInstanceIds();
// Check if there is any media group_content plugin enabled.
$has_media = FALSE;
foreach ($plugin_ids as $plugin_id) {
if (strpos($plugin_id, 'group_media:') === 0) {
// We need at least 1 enabled plugin to have the link.
$has_media = TRUE;
break;
}
}
/** @var \Drupal\group\Entity\GroupInterface $entity */
if ($has_media) {
/** @var \Symfony\Component\Routing\RouterInterface $router */
$router = \Drupal::service('router.no_access_checks');
if ($router
->getRouteCollection()
->get('view.group_media.page_1') !== NULL) {
$operations['media'] = [
'title' => t('Media'),
'weight' => 22,
'url' => Url::fromRoute('view.group_media.page_1', [
'group' => $entity
->id(),
]),
];
}
}
}
return $operations;
}