class RedhenContactRouteContext in RedHen CRM 8
Sets the current contact as context on redhen contact routes.
@todo Remove once core gets a generic EntityRouteContext.
Hierarchy
- class \Drupal\redhen_contact\ContextProvider\RedhenContactRouteContext implements ContextProviderInterface uses StringTranslationTrait
Expanded class hierarchy of RedhenContactRouteContext
1 string reference to 'RedhenContactRouteContext'
- redhen_contact.services.yml in modules/
redhen_contact/ redhen_contact.services.yml - modules/redhen_contact/redhen_contact.services.yml
1 service uses RedhenContactRouteContext
File
- modules/
redhen_contact/ src/ ContextProvider/ RedhenContactRouteContext.php, line 19
Namespace
Drupal\redhen_contact\ContextProviderView source
class RedhenContactRouteContext implements ContextProviderInterface {
use StringTranslationTrait;
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Constructs a new RedhenContactRouteContext object.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*/
public function __construct(RouteMatchInterface $route_match) {
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public function getRuntimeContexts(array $unqualified_context_ids) {
$context_definition = new ContextDefinition('entity:redhen_contact', NULL, FALSE);
$value = NULL;
if ($contact = $this->routeMatch
->getParameter('redhen_contact')) {
$value = $contact;
}
elseif ($this->routeMatch
->getRouteName() == 'entity.redhen_contact.add_form') {
$contact_type = $this->routeMatch
->getParameter('redhen_contact_type');
$value = Contact::create([
'type' => $contact_type
->id(),
]);
}
$cacheability = new CacheableMetadata();
$cacheability
->setCacheContexts([
'route',
]);
$context = new Context($context_definition, $value);
$context
->addCacheableDependency($cacheability);
return [
'redhen_contact' => $context,
];
}
/**
* {@inheritdoc}
*/
public function getAvailableContexts() {
$context = EntityContext::fromEntityTypeId('redhen_contact', $this
->t('Contact from URL'));
return [
'redhen_contact' => $context,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RedhenContactRouteContext:: |
protected | property | The route match. | |
RedhenContactRouteContext:: |
public | function |
Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface:: |
|
RedhenContactRouteContext:: |
public | function |
Gets runtime context values for the given context IDs. Overrides ContextProviderInterface:: |
|
RedhenContactRouteContext:: |
public | function | Constructs a new RedhenContactRouteContext object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
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. |