class WebformSubmissionRouteContext in Webform 6.x
Same name and namespace in other branches
- 8.5 src/ContextProvider/WebformSubmissionRouteContext.php \Drupal\webform\ContextProvider\WebformSubmissionRouteContext
Sets the current webform submission as a context on webform submission routes.
Hierarchy
- class \Drupal\webform\ContextProvider\WebformSubmissionRouteContext implements ContextProviderInterface uses StringTranslationTrait
Expanded class hierarchy of WebformSubmissionRouteContext
1 string reference to 'WebformSubmissionRouteContext'
1 service uses WebformSubmissionRouteContext
File
- src/
ContextProvider/ WebformSubmissionRouteContext.php, line 16
Namespace
Drupal\webform\ContextProviderView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WebformSubmissionRouteContext:: |
protected | property | The route match object. | |
WebformSubmissionRouteContext:: |
public | function |
Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface:: |
|
WebformSubmissionRouteContext:: |
public | function |
Gets runtime context values for the given context IDs. Overrides ContextProviderInterface:: |
|
WebformSubmissionRouteContext:: |
public | function | Constructs a WebformSubmissionRouteContext object. |