You are here

class WebformSubmissionViewController in Webform 8.5

Same name and namespace in other branches
  1. 6.x 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 17

Namespace

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

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

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

  /**
   * Creates an WebformSubmissionViewController object.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer service.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user.
   * @param \Drupal\webform\WebformRequestInterface $webform_request
   *   The webform request handler.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity.manager'), $container
      ->get('renderer'), $container
      ->get('current_user'), $container
      ->get('webform.request'));
  }

  /**
   * {@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->entityManager
      ->getTranslationFromContext($webform_submission)
      ->label();
    return $duplicate ? $this
      ->t('Duplicate @title', [
      '@title' => $title,
    ]) : $title;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
EntityViewController::$deprecatedProperties protected property
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.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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::$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
WebformSubmissionViewController::__construct public function Creates an WebformSubmissionViewController object. Overrides EntityViewController::__construct