You are here

protected function WebformSubmissionListBuilder::buildSubmissionViews in Webform 8.5

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

Build the webform submission view.

Return value

array A renderable array containing a submission view.

1 call to WebformSubmissionListBuilder::buildSubmissionViews()
WebformSubmissionListBuilder::render in src/WebformSubmissionListBuilder.php
Builds the entity listing as renderable array for table.html.twig.

File

src/WebformSubmissionListBuilder.php, line 472

Class

WebformSubmissionListBuilder
Provides a list controller for webform submission entity.

Namespace

Drupal\webform

Code

protected function buildSubmissionViews() {
  $settings = $this->submissionViews[$this->submissionView];

  // Get view name and display id.
  list($name, $display_id) = explode(':', $settings['view']);

  // Load the view and set custom property used to fix the exposed
  // filter action.
  // @see webform_form_views_exposed_form_alter()
  $view = Views::getView($name);
  $view->webform_submission_view = TRUE;

  // Get the current display or default arguments.
  $displays = $view->storage
    ->get('display');
  if (!empty($displays[$display_id]['display_options']['arguments'])) {
    $display_arguments = $displays[$display_id]['display_options']['arguments'];
  }
  elseif (!empty($displays['default']['display_options']['arguments'])) {
    $display_arguments = $displays['default']['display_options']['arguments'];
  }
  else {
    $display_arguments = [];
  }

  // Populate the views arguments.
  $arguments = [];
  foreach ($display_arguments as $argument_name => $display_argument) {
    if ($display_argument['table'] === 'webform_submission') {
      switch ($argument_name) {
        case 'webform_id':
          $arguments[] = isset($this->webform) ? $this->webform
            ->id() : 'all';
          break;
        case 'entity_type':
          $arguments[] = isset($this->sourceEntity) ? $this->sourceEntity
            ->getEntityTypeId() : 'all';
          break;
        case 'entity_id':
          $arguments[] = isset($this->sourceEntity) ? $this->sourceEntity
            ->id() : 'all';
          break;
        case 'uid':
          $arguments[] = isset($this->account) ? $this->account
            ->id() : 'all';
          break;
        case 'in_draft':
          $arguments[] = isset($this->draft) ? $this->draft ? '1' : '0' : 'all';
          break;
        default:
          $arguments[] = 'all';
          break;
      }
    }
  }
  $build = [];
  $build['view'] = [
    '#type' => 'view',
    '#view' => $view,
    '#display_id' => $display_id,
    '#arguments' => $arguments,
  ];
  return $build;
}