You are here

class WebformSubmissionViewController in Webform 6.x

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

Defines a controller to render a single webform submission.

Hierarchy

Expanded class hierarchy of WebformSubmissionViewController

File

src/Controller/WebformSubmissionViewController.php, line 13

Namespace

Drupal\webform\Controller
View source
class WebformSubmissionViewController extends EntityViewController {
  use StringTranslationTrait;

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * The entity repository.
   *
   * @var \Drupal\Core\Entity\EntityRepositoryInterface
   */
  protected $entityRepository;

  /**
   * The webform request handler.
   *
   * @var \Drupal\webform\WebformRequestInterface
   */
  protected $requestHandler;

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * The _title_callback for the page that renders a single webform submission.
   *
   * @param \Drupal\Core\Entity\EntityInterface $webform_submission
   *   The current webform submission.
   * @param bool $duplicate
   *   Flag indicating if submission is being duplicated.
   *
   * @return string
   *   The page title.
   */
  public function title(EntityInterface $webform_submission, $duplicate = FALSE) {
    $title = $this->entityRepository
      ->getTranslationFromContext($webform_submission)
      ->label();
    return $duplicate ? $this
      ->t('Duplicate @title', [
      '@title' => $title,
    ]) : $title;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityViewController::$entityTypeManager protected property The entity type manager.
EntityViewController::$renderer protected property The renderer service.
EntityViewController::buildTitle public function Pre-render callback to build the page title.
EntityViewController::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
EntityViewController::viewRevision public function Provides a page to render a single entity revision.
EntityViewController::__construct public function Creates an EntityViewController object. 2
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.
WebformSubmissionViewController::$currentUser protected property The current user.
WebformSubmissionViewController::$entityRepository protected property The entity repository.
WebformSubmissionViewController::$requestHandler protected property The webform request handler.
WebformSubmissionViewController::create public static function Instantiates a new instance of this class. Overrides EntityViewController::create
WebformSubmissionViewController::title public function The _title_callback for the page that renders a single webform submission.
WebformSubmissionViewController::view public function Provides a page to render a single entity. Overrides EntityViewController::view