WebformSubmissionViewController.php in Webform 6.x
File
src/Controller/WebformSubmissionViewController.php
View source
<?php
namespace Drupal\webform\Controller;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Controller\EntityViewController;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformSubmissionViewController extends EntityViewController {
use StringTranslationTrait;
protected $currentUser;
protected $entityRepository;
protected $requestHandler;
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->currentUser = $container
->get('current_user');
$instance->entityRepository = $container
->get('entity.repository');
$instance->requestHandler = $container
->get('webform.request');
return $instance;
}
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->entityRepository
->getTranslationFromContext($webform_submission)
->label();
return $duplicate ? $this
->t('Duplicate @title', [
'@title' => $title,
]) : $title;
}
}