You are here

class WebformSubmissionRouteContext in Webform 6.x

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

Sets the current webform submission as a context on webform submission routes.

Hierarchy

Expanded class hierarchy of WebformSubmissionRouteContext

1 string reference to 'WebformSubmissionRouteContext'
webform.services.yml in ./webform.services.yml
webform.services.yml
1 service uses WebformSubmissionRouteContext
webform.webform_submission_route_context in ./webform.services.yml
Drupal\webform\ContextProvider\WebformSubmissionRouteContext

File

src/ContextProvider/WebformSubmissionRouteContext.php, line 16

Namespace

Drupal\webform\ContextProvider
View source
class WebformSubmissionRouteContext implements ContextProviderInterface {
  use StringTranslationTrait;

  /**
   * The route match object.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Constructs a WebformSubmissionRouteContext object.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match object.
   */
  public function __construct(RouteMatchInterface $route_match) {
    $this->routeMatch = $route_match;
  }

  /**
   * {@inheritdoc}
   */
  public function getRuntimeContexts(array $unqualified_context_ids) {
    $context_definition = EntityContextDefinition::fromEntityTypeId('webform_submission')
      ->setLabel(NULL)
      ->setRequired(FALSE);
    $value = NULL;
    if (($route_object = $this->routeMatch
      ->getRouteObject()) && ($route_contexts = $route_object
      ->getOption('parameters')) && isset($route_contexts['webform_submission'])) {
      if ($webform_submission = $this->routeMatch
        ->getParameter('webform_submission')) {
        $value = $webform_submission;
      }
    }
    $cacheability = new CacheableMetadata();
    $cacheability
      ->setCacheContexts([
      'route',
    ]);
    $context = new Context($context_definition, $value);
    $context
      ->addCacheableDependency($cacheability);
    return [
      'webform_submission' => $context,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getAvailableContexts() {
    $context = EntityContext::fromEntityTypeId('webform_submission', $this
      ->t('Webform submission from URL'));
    return [
      'webform_submission' => $context,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
WebformSubmissionRouteContext::$routeMatch protected property The route match object.
WebformSubmissionRouteContext::getAvailableContexts public function Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface::getAvailableContexts
WebformSubmissionRouteContext::getRuntimeContexts public function Gets runtime context values for the given context IDs. Overrides ContextProviderInterface::getRuntimeContexts
WebformSubmissionRouteContext::__construct public function Constructs a WebformSubmissionRouteContext object.