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