private function CacheInvalidator::getTagsBySourcePath in Decoupled Router 8
Same name and namespace in other branches
- 2.x src/CacheInvalidator.php \Drupal\decoupled_router\CacheInvalidator::getTagsBySourcePath()
Invalidates cache for an entity based on its internal system path.
Derives the entity associated with the given path (if any) and collects the cache tags associated with it.
Parameters
string $source_path: An internal system path.
Return value
string[] The merged array of cache tags, if any.
Throws
\Drupal\Component\Plugin\Exception\PluginException
1 call to CacheInvalidator::getTagsBySourcePath()
- CacheInvalidator::invalidateByPath in src/
CacheInvalidator.php - Invalidate cached responses associated with the given path.
File
- src/
CacheInvalidator.php, line 76
Class
- CacheInvalidator
- Invalidates decoupled router cache entries based on path events.
Namespace
Drupal\decoupled_routerCode
private function getTagsBySourcePath($source_path) {
$tags = [];
try {
$parameters = Url::fromUri('internal:' . $source_path)
->getRouteParameters();
} catch (\UnexpectedValueException $exception) {
$parameters = [];
}
if (empty($parameters)) {
return $tags;
}
$entity_type_id = key($parameters);
$entity_id = reset($parameters);
if (empty($entity_type_id) || empty($entity_id)) {
return $tags;
}
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id, FALSE);
if (!$entity_type) {
return $tags;
}
$entity = $this->entityTypeManager
->getStorage($entity_type_id)
->load($entity_id);
if (!$entity) {
return $tags;
}
$tags = Cache::mergeTags($entity_type
->getListCacheTags(), $entity
->getCacheTagsToInvalidate());
return $tags;
}