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