AddMenuCacheflush.php in CacheFlush 8
File
modules/cacheflush_ui/src/Plugin/Action/AddMenuCacheflush.php
View source
<?php
namespace Drupal\cacheflush_ui\Plugin\Action;
use Drupal\cacheflush_ui\CacheflushUIConstantsInterface;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Routing\RouteBuilderInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AddMenuCacheflush extends ActionBase {
protected $routerBuilder;
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteBuilderInterface $router_builder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routerBuilder = $router_builder;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('router.builder'));
}
public function executeMultiple(array $entities) {
foreach ($entities as $entity) {
$this
->execute($entity);
}
$this->routerBuilder
->rebuild();
}
public function execute($entity = NULL) {
$entity->menu = CacheflushUIConstantsInterface::CACHEFLUSH_MENU;
$entity
->save();
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = $object
->access('update', $account, TRUE);
return $return_as_object ? $result : $result
->isAllowed();
}
}