View source
<?php
namespace Drupal\webform\Controller;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Controller\EntityViewController;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\webform\WebformRequestInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformSubmissionViewController extends EntityViewController {
use StringTranslationTrait;
protected $currentUser;
protected $requestHandler;
public function __construct(EntityManagerInterface $entity_manager, RendererInterface $renderer, AccountInterface $current_user, WebformRequestInterface $webform_request) {
parent::__construct($entity_manager, $renderer);
$this->currentUser = $current_user;
$this->requestHandler = $webform_request;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.manager'), $container
->get('renderer'), $container
->get('current_user'), $container
->get('webform.request'));
}
public function view(EntityInterface $webform_submission, $view_mode = 'default', $langcode = NULL) {
$webform = $this->requestHandler
->getCurrentWebform();
$source_entity = $this->requestHandler
->getCurrentSourceEntity('webform_submission');
$build = [
'#theme' => 'webform_submission',
'#view_mode' => $view_mode,
'#webform_submission' => $webform_submission,
];
$build['navigation'] = [
'#type' => 'webform_submission_navigation',
'#webform_submission' => $webform_submission,
];
$build['information'] = [
'#type' => 'webform_submission_information',
'#webform_submission' => $webform_submission,
'#source_entity' => $source_entity,
];
$build['submission'] = parent::view($webform_submission, $view_mode, $langcode);
$build['#attached']['library'][] = 'webform/webform.admin';
$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;
}
public function title(EntityInterface $webform_submission, $duplicate = FALSE) {
$title = $this->entityManager
->getTranslationFromContext($webform_submission)
->label();
return $duplicate ? $this
->t('Duplicate @title', [
'@title' => $title,
]) : $title;
}
}