class MicrositeCacheContext in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 modules/entity_hierarchy_microsite/src/Cache/MicrositeCacheContext.php \Drupal\entity_hierarchy_microsite\Cache\MicrositeCacheContext
Defines a class for a microsite cache context.
Hierarchy
- class \Drupal\entity_hierarchy_microsite\Cache\MicrositeCacheContext implements CacheContextInterface
Expanded class hierarchy of MicrositeCacheContext
1 string reference to 'MicrositeCacheContext'
- entity_hierarchy_microsite.services.yml in modules/
entity_hierarchy_microsite/ entity_hierarchy_microsite.services.yml - modules/entity_hierarchy_microsite/entity_hierarchy_microsite.services.yml
1 service uses MicrositeCacheContext
- cache_context.entity_hierarchy_microsite in modules/
entity_hierarchy_microsite/ entity_hierarchy_microsite.services.yml - Drupal\entity_hierarchy_microsite\Cache\MicrositeCacheContext
File
- modules/
entity_hierarchy_microsite/ src/ Cache/ MicrositeCacheContext.php, line 15
Namespace
Drupal\entity_hierarchy_microsite\CacheView source
class MicrositeCacheContext implements CacheContextInterface {
const NOT_A_MICROSITE = -1;
/**
* Lookup.
*
* @var \Drupal\entity_hierarchy_microsite\ChildOfMicrositeLookupInterface
*/
private $childOfMicrositeLookup;
/**
* Route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
private $routeMatch;
/**
* Parent candidate.
*
* @var \Drupal\entity_hierarchy\Information\ParentCandidateInterface
*/
private $parentCandidate;
/**
* Constructs a new MicrositeCacheContext.
*
* @param \Drupal\entity_hierarchy_microsite\ChildOfMicrositeLookupInterface $childOfMicrositeLookup
* Lookup.
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
* Route match.
* @param \Drupal\entity_hierarchy\Information\ParentCandidateInterface $parentCandidate
* Parent candidate.
*/
public function __construct(ChildOfMicrositeLookupInterface $childOfMicrositeLookup, RouteMatchInterface $routeMatch, ParentCandidateInterface $parentCandidate) {
$this->childOfMicrositeLookup = $childOfMicrositeLookup;
$this->routeMatch = $routeMatch;
$this->parentCandidate = $parentCandidate;
}
/**
* {@inheritdoc}
*/
public static function getLabel() {
return 'Microsite ID';
}
/**
* {@inheritdoc}
*/
public function getContext() {
$node = $this->routeMatch
->getParameter('node');
if (!$node || !$node instanceof NodeInterface) {
return self::NOT_A_MICROSITE;
}
if (!($fields = $this->parentCandidate
->getCandidateFields($node))) {
return self::NOT_A_MICROSITE;
}
foreach ($fields as $field_name) {
if ($microsites = $this->childOfMicrositeLookup
->findMicrositesForNodeAndField($node, $field_name)) {
return implode(':', array_keys($microsites));
}
}
return self::NOT_A_MICROSITE;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MicrositeCacheContext:: |
private | property | Lookup. | |
MicrositeCacheContext:: |
private | property | Parent candidate. | |
MicrositeCacheContext:: |
private | property | Route match. | |
MicrositeCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
MicrositeCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
MicrositeCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
MicrositeCacheContext:: |
constant | |||
MicrositeCacheContext:: |
public | function | Constructs a new MicrositeCacheContext. |