protected function MenuTreeResource::addCacheDependencies in REST Menu Tree 2.x
Same name and namespace in other branches
- 8 src/Plugin/rest/resource/MenuTreeResource.php \Drupal\rest_menu_tree\Plugin\rest\resource\MenuTreeResource::addCacheDependencies()
Add Cache Tags.
1 call to MenuTreeResource::addCacheDependencies()
- MenuTreeResource::get in src/
Plugin/ rest/ resource/ MenuTreeResource.php
File
- src/
Plugin/ rest/ resource/ MenuTreeResource.php, line 183
Class
- MenuTreeResource
- Provides a resource to get view modes by entity and bundle.
Namespace
Drupal\rest_menu_tree\Plugin\rest\resourceCode
protected function addCacheDependencies(array $data, CacheableResponseInterface $response) {
foreach ($data as $value) {
// Gather the access cacheability of every item in the menu link tree,
// including inaccessible items. This allows us to render cache the menu
// tree, yet still automatically vary the rendered menu by the same cache
// contexts that the access results vary by.
// However, if $value->access is not an AccessResultInterface object, this
// will still render the menu link, because this method does not want to
// require access checking to be able to render a menu tree.
if ($value->access instanceof AccessResultInterface) {
$response
->addCacheableDependency($value->access);
}
// Gather the cacheability of every item in the menu link tree. Some links
// may be dynamic: they may have a dynamic text (e.g. a "Hi, <user>" link
// text, which would vary by 'user' cache context), or a dynamic route
// name or route parameters.
$response
->addCacheableDependency($value->link);
// There may be additional dependencies that must be manually determined.
$this
->addLinkCacheDependencies($value->link, $response);
if ($value->subtree) {
$this
->addCacheDependencies($value->subtree, $response);
}
}
}