You are here

protected function GroupContentMenuListBuilder::getDefaultOperations in Group Content Menu 8

Gets this list's default operations.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the operations are for.

Return value

array The array structure is identical to the return value of self::getOperations().

Overrides EntityListBuilder::getDefaultOperations

File

src/GroupContentMenuListBuilder.php, line 98

Class

GroupContentMenuListBuilder
Provides a list controller for the group content menu entity type.

Namespace

Drupal\group_content_menu

Code

protected function getDefaultOperations(EntityInterface $entity) {
  $operations = parent::getDefaultOperations($entity);

  /** @var \Drupal\group\Entity\GroupContentInterface[] $group_contents */
  $group_contents = \Drupal::entityTypeManager()
    ->getStorage('group_content')
    ->loadByEntity($entity);
  if ($group_content = reset($group_contents)) {
    $entity_type_id = $entity
      ->getEntityTypeId();
    $account = \Drupal::currentUser()
      ->getAccount();
    if ($entity
      ->hasLinkTemplate('edit-form') && $group_content
      ->getGroup()
      ->hasPermission("update own group_content_menu:{$entity_type_id} entity", $account)) {
      $operations['edit'] = [
        'title' => $this
          ->t('Edit'),
        'weight' => 10,
        'url' => $this
          ->ensureDestination($entity
          ->toUrl('edit-form')),
      ];
    }
    if ($entity
      ->hasLinkTemplate('delete-form') && $group_content
      ->getGroup()
      ->hasPermission("delete own group_content_menu:{$entity_type_id} entity", $account)) {
      $operations['delete'] = [
        'title' => $this
          ->t('Delete'),
        'weight' => 100,
        'url' => $this
          ->ensureDestination($entity
          ->toUrl('delete-form')),
      ];
    }
  }
  return $operations;
}