You are here

public function WebformSubmissionViewController::view in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Controller/WebformSubmissionViewController.php \Drupal\webform\Controller\WebformSubmissionViewController::view()

Provides a page to render a single entity.

Parameters

\Drupal\Core\Entity\EntityInterface $_entity: The Entity to be rendered. Note this variable is named $_entity rather than $entity to prevent collisions with other named placeholders in the route.

string $view_mode: (optional) The view mode that should be used to display the entity. Defaults to 'full'.

Return value

array A render array as expected by \Drupal\Core\Render\RendererInterface::render().

Overrides EntityViewController::view

2 string references to 'WebformSubmissionViewController::view'
webform.routing.yml in ./webform.routing.yml
webform.routing.yml
webform_node.routing.yml in modules/webform_node/webform_node.routing.yml
modules/webform_node/webform_node.routing.yml

File

src/Controller/WebformSubmissionViewController.php, line 52

Class

WebformSubmissionViewController
Defines a controller to render a single webform submission.

Namespace

Drupal\webform\Controller

Code

public function view(EntityInterface $webform_submission, $view_mode = 'default', $langcode = NULL) {
  $webform = $this->requestHandler
    ->getCurrentWebform();
  $source_entity = $this->requestHandler
    ->getCurrentSourceEntity('webform_submission');

  // Set webform submission template.
  $build = [
    '#theme' => 'webform_submission',
    '#view_mode' => $view_mode,
    '#webform_submission' => $webform_submission,
  ];

  // Navigation.
  $build['navigation'] = [
    '#type' => 'webform_submission_navigation',
    '#webform_submission' => $webform_submission,
  ];

  // Information.
  $build['information'] = [
    '#type' => 'webform_submission_information',
    '#webform_submission' => $webform_submission,
    '#source_entity' => $source_entity,
  ];

  // Submission.
  $build['submission'] = parent::view($webform_submission, $view_mode, $langcode);

  // Library.
  $build['#attached']['library'][] = 'webform/webform.admin';

  // Add entities cacheable dependency.
  $this->renderer
    ->addCacheableDependency($build, $this->currentUser);
  $this->renderer
    ->addCacheableDependency($build, $webform);
  $this->renderer
    ->addCacheableDependency($build, $webform_submission);
  if ($source_entity) {
    $this->renderer
      ->addCacheableDependency($build, $source_entity);
  }
  return $build;
}