You are here

public function WebformSubmissionListBuilder::getDefaultOperations in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformSubmissionListBuilder.php \Drupal\webform\WebformSubmissionListBuilder::getDefaultOperations()

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/WebformSubmissionListBuilder.php, line 1024

Class

WebformSubmissionListBuilder
Provides a list controller for webform submission entity.

Namespace

Drupal\webform

Code

public function getDefaultOperations(EntityInterface $entity) {

  /** @var \Drupal\webform\WebformInterface $webform */
  $webform = $entity
    ->getWebform();
  $operations = [];
  if ($this->account) {
    if ($entity
      ->access('update')) {
      $operations['edit'] = [
        'title' => $this
          ->t('Edit'),
        'weight' => 10,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform.user.submission.edit'),
      ];
    }
    if ($entity
      ->access('view')) {
      $operations['view'] = [
        'title' => $this
          ->t('View'),
        'weight' => 20,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform.user.submission'),
      ];
    }
    if ($entity
      ->access('duplicate') && $webform
      ->getSetting('submission_user_duplicate')) {
      $operations['duplicate'] = [
        'title' => $this
          ->t('Duplicate'),
        'weight' => 23,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform.user.submission.duplicate'),
      ];
    }
    if ($entity
      ->access('delete')) {
      $operations['delete'] = [
        'title' => $this
          ->t('Delete'),
        'weight' => 100,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform.user.submission.delete'),
        'attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW),
      ];
    }
  }
  else {
    if ($entity
      ->access('update')) {
      $operations['edit'] = [
        'title' => $this
          ->t('Edit'),
        'weight' => 10,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform_submission.edit_form'),
      ];
    }
    if ($entity
      ->access('view')) {
      $operations['view'] = [
        'title' => $this
          ->t('View'),
        'weight' => 20,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform_submission.canonical'),
      ];
    }
    if ($entity
      ->access('notes')) {
      $operations['notes'] = [
        'title' => $this
          ->t('Notes'),
        'weight' => 21,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform_submission.notes_form'),
      ];
    }
    if ($entity
      ->access('resend') && $webform
      ->hasMessageHandler()) {
      $operations['resend'] = [
        'title' => $this
          ->t('Resend'),
        'weight' => 22,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform_submission.resend_form'),
      ];
    }
    if ($entity
      ->access('duplicate')) {
      $operations['duplicate'] = [
        'title' => $this
          ->t('Duplicate'),
        'weight' => 23,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform_submission.duplicate_form'),
      ];
    }
    if ($entity
      ->access('delete')) {
      $operations['delete'] = [
        'title' => $this
          ->t('Delete'),
        'weight' => 100,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform_submission.delete_form'),
        'attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW),
      ];
    }
    if ($entity
      ->access('view_any') && $this->currentUser
      ->hasPermission('access webform submission log') && $webform
      ->hasSubmissionLog() && $this->moduleHandler
      ->moduleExists('webform_submission_log')) {
      $operations['log'] = [
        'title' => $this
          ->t('Log'),
        'weight' => 100,
        'url' => $this->requestHandler
          ->getUrl($entity, $this->sourceEntity, 'webform_submission.log'),
      ];
    }
  }

  // Add destination to all operation links.
  foreach ($operations as &$operation) {
    $this
      ->ensureDestination($operation['url']);
  }
  return $operations;
}