class GroupRouteContext in Group 2.0.x
Same name and namespace in other branches
- 8 src/Context/GroupRouteContext.php \Drupal\group\Context\GroupRouteContext
Sets the current group as a context on group routes.
Hierarchy
- class \Drupal\group\Context\GroupRouteContext implements ContextProviderInterface uses StringTranslationTrait, GroupRouteContextTrait
Expanded class hierarchy of GroupRouteContext
1 string reference to 'GroupRouteContext'
1 service uses GroupRouteContext
File
- src/
Context/ GroupRouteContext.php, line 18
Namespace
Drupal\group\ContextView source
class GroupRouteContext implements ContextProviderInterface {
use GroupRouteContextTrait;
use StringTranslationTrait;
/**
* Constructs a new GroupRouteContext.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match
* The current route match object.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(RouteMatchInterface $current_route_match, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->currentRouteMatch = $current_route_match;
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public function getRuntimeContexts(array $unqualified_context_ids) {
// Create an optional context definition for group entities.
$context_definition = EntityContextDefinition::fromEntityTypeId('group')
->setRequired(FALSE);
// Cache this context per group on the route.
$cacheability = new CacheableMetadata();
$cacheability
->setCacheContexts([
'route.group',
]);
// Create a context from the definition and retrieved or created group.
$context = new Context($context_definition, $this
->getGroupFromRoute());
$context
->addCacheableDependency($cacheability);
return [
'group' => $context,
];
}
/**
* {@inheritdoc}
*/
public function getAvailableContexts() {
return [
'group' => EntityContext::fromEntityTypeId('group', $this
->t('Group from URL')),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GroupRouteContext:: |
public | function |
Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface:: |
|
GroupRouteContext:: |
public | function |
Gets runtime context values for the given context IDs. Overrides ContextProviderInterface:: |
|
GroupRouteContext:: |
public | function | Constructs a new GroupRouteContext. | |
GroupRouteContextTrait:: |
protected | property | The current route match object. | |
GroupRouteContextTrait:: |
protected | property | The entity type manager service. | |
GroupRouteContextTrait:: |
protected | function | Gets the current route match object. | |
GroupRouteContextTrait:: |
protected | function | Gets the entity type manager service. | |
GroupRouteContextTrait:: |
public | function | Retrieves the group entity from the current route. | |
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. |