You are here

function opigno_module_entity_operation in Opigno module 8

Same name and namespace in other branches
  1. 3.x opigno_module.module \opigno_module_entity_operation()

Implements hook_entity_operation().

File

./opigno_module.module, line 1179
Contains opigno_module.module.

Code

function opigno_module_entity_operation(\Drupal\Core\Entity\EntityInterface $entity) {
  if (!\Drupal::currentUser()
    ->hasPermission('access content')) {
    return [];
  }
  $entityTypeId = $entity
    ->getEntityTypeId();
  if ($entityTypeId !== 'opigno_module' && $entityTypeId !== 'opigno_activity') {
    return [];
  }
  switch ($entityTypeId) {
    case 'opigno_module':
      $operations['module_results'] = array(
        'title' => t('See Results'),
        'weight' => 14,
        'url' => Url::fromRoute('view.opigno_module_results.opigno_module_results', [
          'arg_0' => $entity
            ->id(),
        ]),
      );
      $operations['duplicate_module'] = array(
        'title' => t('Duplicate'),
        'weight' => 15,
        'url' => Url::fromRoute('opigno_module.duplicate', [
          'opigno_module' => $entity
            ->id(),
        ]),
      );
      $operations['export_module'] = array(
        'title' => t('Export'),
        'weight' => 16,
        'url' => Url::fromRoute('opigno_module.export.module', [
          'opigno_module' => $entity
            ->id(),
        ]),
      );
      break;
    case 'opigno_activity':
      $operations['export_activity'] = array(
        'title' => t('Export'),
        'weight' => 15,
        'url' => Url::fromRoute('opigno_module.export.activity', [
          'opigno_activity' => $entity
            ->id(),
        ]),
      );
      break;
  }
  return $operations;
}