gcommerce-8.x-1.0-beta5/modules/gcommerce_promotion/gcommerce_promotion.module
modules/gcommerce_promotion/gcommerce_promotion.module
<?php
/**
* @file
* Enables Group functionality for the Commerce Promotions.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\group\Entity\GroupInterface;
use Symfony\Component\Routing\RouterInterface;
/**
* Implements hook_entity_operation().
*/
function gcommerce_promotion_entity_operation(EntityInterface $entity) {
$operations = [];
if ($entity->getEntityTypeId() === 'group' && \Drupal::moduleHandler()->moduleExists('views')) {
assert($entity instanceof GroupInterface);
if ($entity->hasPermission('access group_promotion overview', \Drupal::currentUser())) {
$router = \Drupal::service('router.no_access_checks');
assert($router instanceof RouterInterface);
if ($router->getRouteCollection()->get('view.group_promotions.page_1') !== NULL) {
$operations['promotions'] = [
'title' => t('Promotions'),
'weight' => 20,
'url' => Url::fromRoute('view.group_promotions.page_1', ['group' => $entity->id()]),
];
}
}
}
return $operations;
}
