RestMenuItemsCacheableDependency.php in Rest menu items 8.2
File
src/Plugin/rest/resource/RestMenuItemsCacheableDependency.php
View source
<?php
namespace Drupal\rest_menu_items\Plugin\rest\resource;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\Cache;
class RestMenuItemsCacheableDependency implements CacheableDependencyInterface {
protected $minDepth = 1;
protected $maxDepth = 1;
protected $menuName = '';
public function __construct($menuName, $minDepth, $maxDepth) {
$this->menuName = $menuName;
$this->minDepth = $minDepth;
$this->maxDepth = $maxDepth;
}
public function getCacheContexts() {
$contexts = [];
if ($this->minDepth != 1 || $this->maxDepth != 1) {
$contexts[] = 'url.query_args';
$contexts[] = 'user.permissions';
}
return $contexts;
}
public function getCacheTags() {
$tags = [];
$tags[] = 'config:system.menu.' . $this->menuName;
return $tags;
}
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
}