ToolbarController.php in Admin Toolbar 8.2
File
admin_toolbar_tools/src/Controller/ToolbarController.php
View source
<?php
namespace Drupal\admin_toolbar_tools\Controller;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\CronInterface;
use Drupal\Core\Menu\ContextualLinkManager;
use Drupal\Core\Menu\LocalActionManager;
use Drupal\Core\Menu\LocalTaskManager;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\Template\TwigEnvironment;
use Drupal\Core\Theme\Registry;
class ToolbarController extends ControllerBase {
protected $cron;
protected $menuLinkManager;
protected $contextualLinkManager;
protected $localTaskLinkManager;
protected $localActionLinkManager;
protected $cacheRender;
protected $time;
protected $requestStack;
protected $pluginCacheClearer;
protected $cacheMenu;
protected $twig;
protected $themeRegistry;
public function __construct(CronInterface $cron, MenuLinkManagerInterface $menuLinkManager, ContextualLinkManager $contextualLinkManager, LocalTaskManager $localTaskLinkManager, LocalActionManager $localActionLinkManager, CacheBackendInterface $cacheRender, TimeInterface $time, RequestStack $request_stack, CachedDiscoveryClearerInterface $plugin_cache_clearer, CacheBackendInterface $cache_menu, TwigEnvironment $twig, Registry $theme_registry) {
$this->cron = $cron;
$this->menuLinkManager = $menuLinkManager;
$this->contextualLinkManager = $contextualLinkManager;
$this->localTaskLinkManager = $localTaskLinkManager;
$this->localActionLinkManager = $localActionLinkManager;
$this->cacheRender = $cacheRender;
$this->time = $time;
$this->requestStack = $request_stack;
$this->pluginCacheClearer = $plugin_cache_clearer;
$this->cacheMenu = $cache_menu;
$this->twig = $twig;
$this->themeRegistry = $theme_registry;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('cron'), $container
->get('plugin.manager.menu.link'), $container
->get('plugin.manager.menu.contextual_link'), $container
->get('plugin.manager.menu.local_task'), $container
->get('plugin.manager.menu.local_action'), $container
->get('cache.render'), $container
->get('datetime.time'), $container
->get('request_stack'), $container
->get('plugin.cache_clearer'), $container
->get('cache.menu'), $container
->get('twig'), $container
->get('theme.registry'));
}
public function reloadPage() {
$request = $this->requestStack
->getCurrentRequest();
if ($request->server
->get('HTTP_REFERER')) {
return $request->server
->get('HTTP_REFERER');
}
else {
return '/';
}
}
public function flushAll() {
$this
->messenger()
->addMessage($this
->t('All caches cleared.'));
drupal_flush_all_caches();
return new RedirectResponse($this
->reloadPage());
}
public function flushJsCss() {
$this
->state()
->set('system.css_js_query_string', base_convert($this->time
->getCurrentTime(), 10, 36));
$this
->messenger()
->addMessage($this
->t('CSS and JavaScript cache cleared.'));
return new RedirectResponse($this
->reloadPage());
}
public function flushPlugins() {
$this->pluginCacheClearer
->clearCachedDefinitions();
$this
->messenger()
->addMessage($this
->t('Plugins cache cleared.'));
return new RedirectResponse($this
->reloadPage());
}
public function flushStatic() {
drupal_static_reset();
$this
->messenger()
->addMessage($this
->t('Static cache cleared.'));
return new RedirectResponse($this
->reloadPage());
}
public function flushMenu() {
$this->cacheMenu
->invalidateAll();
$this->menuLinkManager
->rebuild();
$this->contextualLinkManager
->clearCachedDefinitions();
$this->localTaskLinkManager
->clearCachedDefinitions();
$this->localActionLinkManager
->clearCachedDefinitions();
$this
->messenger()
->addMessage($this
->t('Routing and links cache cleared.'));
return new RedirectResponse($this
->reloadPage());
}
public function flushViews() {
views_invalidate_cache();
$this
->messenger()
->addMessage($this
->t('Views cache cleared.'));
return new RedirectResponse($this
->reloadPage());
}
public function flushTwig() {
$this->twig
->invalidate();
$this
->messenger()
->addMessage($this
->t('Twig cache cleared.'));
return new RedirectResponse($this
->reloadPage());
}
public function runCron() {
$this->cron
->run();
$this
->messenger()
->addMessage($this
->t('Cron ran successfully.'));
return new RedirectResponse($this
->reloadPage());
}
public function cacheRender() {
$this->cacheRender
->invalidateAll();
$this
->messenger()
->addMessage($this
->t('Render cache cleared.'));
return new RedirectResponse($this
->reloadPage());
}
public function themeRebuild() {
$this->themeRegistry
->reset();
$this
->messenger()
->addMessage($this
->t('Theme registry rebuilded.'));
return new RedirectResponse($this
->reloadPage());
}
}