You are here

public function WebformSubmissionListBuilder::__construct in Webform 8.5

Constructs a new WebformSubmissionListBuilder object.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage class.

\Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager: The entity type manager.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.

\Symfony\Component\HttpFoundation\RequestStack $request_stack: The request stack.

\Drupal\Core\Session\AccountInterface $current_user: The current user.

\Drupal\Core\Config\ConfigFactoryInterface $config_factory: The configuration factory.

\Drupal\webform\WebformRequestInterface $webform_request: The webform request handler.

\Drupal\webform\Plugin\WebformElementManagerInterface $element_manager: The webform element manager.

\Drupal\webform\WebformMessageManagerInterface $message_manager: The webform message manager.

Overrides EntityListBuilder::__construct

File

src/WebformSubmissionListBuilder.php, line 293

Class

WebformSubmissionListBuilder
Provides a list controller for webform submission entity.

Namespace

Drupal\webform

Code

public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityTypeManagerInterface $entity_type_manager, RouteMatchInterface $route_match, RequestStack $request_stack, AccountInterface $current_user, ConfigFactoryInterface $config_factory, WebformRequestInterface $webform_request, WebformElementManagerInterface $element_manager, WebformMessageManagerInterface $message_manager) {
  parent::__construct($entity_type, $storage);
  $this->entityTypeManager = $entity_type_manager;
  $this->routeMatch = $route_match;
  $this->request = $request_stack
    ->getCurrentRequest();
  $this->currentUser = $current_user;
  $this->configFactory = $config_factory;
  $this->requestHandler = $webform_request;
  $this->elementManager = $element_manager;
  $this->messageManager = $message_manager;
  $this->keys = $this->request->query
    ->get('search');
  $this->state = $this->request->query
    ->get('state');
  $this->sourceEntityTypeId = $this->request->query
    ->get('entity');
  list($this->webform, $this->sourceEntity) = $this->requestHandler
    ->getWebformEntities();
  $this->messageManager
    ->setWebform($this->webform);
  $this->messageManager
    ->setSourceEntity($this->sourceEntity);

  /** @var WebformSubmissionStorageInterface $webform_submission_storage */
  $webform_submission_storage = $this
    ->getStorage();
  $route_name = $this->routeMatch
    ->getRouteName();
  $base_route_name = $this->webform ? $this->requestHandler
    ->getBaseRouteName($this->webform, $this->sourceEntity) : '';

  // Set account and state based on the current route.
  switch ($route_name) {
    case 'entity.webform_submission.user':
      $this->account = $this->routeMatch
        ->getParameter('user');
      break;
    case "{$base_route_name}.webform.user.submissions":
      $this->account = $this->currentUser;
      $this->draft = FALSE;
      break;
    case "{$base_route_name}.webform.user.drafts":
      $this->account = $this->currentUser;
      $this->draft = TRUE;
      break;
    default:
      $this->account = NULL;
      break;
  }

  // Initialize submission views and view.
  $this->submissionView = $this->routeMatch
    ->getParameter('submission_view') ?: '';
  $this->submissionViews = $this
    ->getSubmissionViews();
  if ($this->submissionViews && empty($this->submissionView) && $this
    ->isSubmissionViewResultsReplaced()) {
    $this->submissionView = WebformArrayHelper::getFirstKey($this->submissionViews);
  }

  // Check submission view access.
  if ($this->submissionView && !isset($this->submissionViews[$this->submissionView])) {
    $submission_views = $this
      ->getSubmissionViewsConfig();
    if (isset($submission_views[$this->submissionView])) {
      throw new AccessDeniedHttpException();
    }
    else {
      throw new NotFoundHttpException();
    }
  }

  // If there is a submission view, we do not need to initialize
  // the entity list.
  if ($this->submissionView) {
    return;
  }

  // Set default display settings.
  $this->direction = 'desc';
  $this->limit = 20;
  $this->customize = FALSE;
  $this->sort = 'created';
  $this->total = $this
    ->getTotal($this->keys, $this->state, $this->sourceEntityTypeId);
  switch ($route_name) {

    // Display webform submissions which includes properties and elements.
    // @see /admin/structure/webform/manage/{webform}/results/submissions
    // @see /node/{node}/webform/results/submissions
    case "{$base_route_name}.webform.results_submissions":
      $this->columns = $webform_submission_storage
        ->getCustomColumns($this->webform, $this->sourceEntity, $this->account, TRUE);
      $this->sort = $this
        ->getCustomSetting('sort', 'created');
      $this->direction = $this
        ->getCustomSetting('direction', 'desc');
      $this->limit = $this
        ->getCustomSetting('limit', 20);
      $this->format = $this
        ->getCustomSetting('format', $this->format);
      $this->linkType = $this
        ->getCustomSetting('link_type', $this->linkType);
      $this->customize = $this->webform
        ->access('update') || $this->webform
        ->getSetting('results_customize', TRUE);
      if ($this->format['element_format'] === 'raw') {
        foreach ($this->columns as &$column) {
          $column['format'] = 'raw';
          if (isset($column['element'])) {
            $column['element']['#format'] = 'raw';
          }
        }
      }
      break;

    // Display all submissions.
    // @see /admin/structure/webform/submissions/manage
    case 'entity.webform_submission.collection':

      // Display only submission properties.
      // @see /admin/structure/webform/submissions/manage
      $this->columns = $webform_submission_storage
        ->getSubmissionsColumns();
      break;

    // Display user's submissions.
    // @see /user/{user}/submissions
    case 'entity.webform_submission.user':
      $this->columns = $webform_submission_storage
        ->getUsersSubmissionsColumns();
      break;

    // Display user's submissions.
    // @see /webform/{webform}/submissions
    // @see /webform/{webform}/drafts
    // @see /node/{node}/webform/submissions
    // @see /node/{node}/webform/drafts
    case "{$base_route_name}.webform.user.drafts":
    case "{$base_route_name}.webform.user.submissions":
    default:
      $this->columns = $webform_submission_storage
        ->getUserColumns($this->webform, $this->sourceEntity, $this->account, TRUE);
      break;
  }
}