You are here

function opigno_group_manager_entity_operation in Opigno group manager 3.x

Same name and namespace in other branches
  1. 8 opigno_group_manager.module \opigno_group_manager_entity_operation()

Implements hook_entity_operation().

File

./opigno_group_manager.module, line 212
Contains opigno_group_manager.module.

Code

function opigno_group_manager_entity_operation(\Drupal\Core\Entity\EntityInterface $entity) {
  if (!\Drupal::currentUser()
    ->hasPermission('access content')) {
    return [];
  }
  $entityTypeId = $entity
    ->getEntityTypeId();
  $entityBundle = $entity
    ->bundle();
  if ($entityTypeId !== 'group') {
    return [];
  }
  $operations = [];
  switch ($entityBundle) {
    case 'opigno_course':
      $operations['duplicate'] = array(
        'title' => t('Duplicate'),
        'weight' => 15,
        'url' => Url::fromRoute('opigno_group.course_duplicate', [
          'group' => $entity
            ->id(),
        ]),
      );
      $operations['export_course'] = array(
        'title' => t('Export'),
        'weight' => 16,
        'url' => Url::fromRoute('opigno_group.course_export', [
          'group' => $entity
            ->id(),
        ]),
      );
      break;
    case 'learning_path':
      $operations['duplicate'] = array(
        'title' => t('Duplicate'),
        'weight' => 15,
        'url' => Url::fromRoute('opigno_group.training_duplicate', [
          'group' => $entity
            ->id(),
        ]),
      );
      $operations['export_training'] = array(
        'title' => t('Export'),
        'weight' => 16,
        'url' => Url::fromRoute('opigno_group.training_export', [
          'group' => $entity
            ->id(),
        ]),
      );
      break;
  }
  return $operations;
}