3 namespace Drupal\admin_toolbar_tools\Controller;
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Controller\ControllerBase;
7 use Drupal\Core\CronInterface;
8 use Drupal\Core\Routing\TrustedRedirectResponse;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10 use Symfony\Component\HttpFoundation\RedirectResponse;
11 use Drupal\Core\Menu\ContextualLinkManager;
12 use Drupal\Core\Menu\LocalActionManager;
13 use Drupal\Core\Menu\LocalTaskManager;
14 use Drupal\Core\Menu\MenuLinkManager;
17 * Class ToolbarController
19 * @package Drupal\admin_toolbar_tools\Controller
21 class ToolbarController extends ControllerBase {
26 * @var $cron \Drupal\Core\CronInterface
29 protected $menuLinkManager;
30 protected $contextualLinkManager;
31 protected $localTaskLinkManager;
32 protected $localActionLinkManager;
33 protected $cacheRender;
36 * Constructs a CronController object.
38 * @param \Drupal\Core\CronInterface $cron
41 public function __construct(CronInterface $cron,
42 MenuLinkManager $menuLinkManager,
43 ContextualLinkManager $contextualLinkManager,
44 LocalTaskManager $localTaskLinkManager,
45 LocalActionManager $localActionLinkManager,
46 CacheBackendInterface $cacheRender) {
48 $this->menuLinkManager = $menuLinkManager;
49 $this->contextualLinkManager = $contextualLinkManager;
50 $this->localTaskLinkManager = $localTaskLinkManager;
51 $this->localActionLinkManager = $localActionLinkManager;
52 $this->cacheRender = $cacheRender;
58 public static function create(ContainerInterface $container) {
60 $container->get('cron'),
61 $container->get('plugin.manager.menu.link'),
62 $container->get('plugin.manager.menu.contextual_link'),
63 $container->get('plugin.manager.menu.local_task'),
64 $container->get('plugin.manager.menu.local_action'),
65 $container->get('cache.render')
70 * Reload the previous page.
72 public function reload_page() {
73 $request = \Drupal::request();
74 if ($request->server->get('HTTP_REFERER')) {
75 return $request->server->get('HTTP_REFERER');
85 public function flushAll() {
86 drupal_flush_all_caches();
87 drupal_set_message($this->t('All caches cleared.'));
88 return new RedirectResponse($this->reload_page());
92 * Flushes css and javascript caches.
94 public function flush_js_css() {
96 ->set('system.css_js_query_string', base_convert(REQUEST_TIME, 10, 36));
97 drupal_set_message($this->t('CSS and JavaScript cache cleared.'));
98 return new RedirectResponse($this->reload_page());
102 * Flushes plugins caches.
104 public function flush_plugins() {
105 \Drupal::service('plugin.cache_clearer')->clearCachedDefinitions();
106 drupal_set_message($this->t('Plugins cache cleared.'));
107 return new RedirectResponse($this->reload_page());
111 * Resets all static caches.
113 public function flush_static() {
114 drupal_static_reset();
115 drupal_set_message($this->t('Static cache cleared.'));
116 return new RedirectResponse($this->reload_page());
120 * Clears all cached menu data.
122 public function flush_menu() {
123 menu_cache_clear_all();
124 $this->menuLinkManager->rebuild();
125 $this->contextualLinkManager->clearCachedDefinitions();
126 $this->localTaskLinkManager->clearCachedDefinitions();
127 $this->localActionLinkManager->clearCachedDefinitions();
128 drupal_set_message($this->t('Routing and links cache cleared.'));
129 return new RedirectResponse($this->reload_page());
133 * Links to drupal.org home page.
135 public function drupal_org() {
136 $response = new TrustedRedirectResponse("https://www.drupal.org");
142 * Displays the administration link Development.
144 public function development() {
145 return new RedirectResponse('/admin/structure/menu/');
149 * Access to Drupal 8 changes.
150 * (list changes of the different versions of drupal core).
152 public function list_changes() {
153 $response = new TrustedRedirectResponse("https://www.drupal.org/list-changes");
159 * Adds a link to the Drupal 8 documentation.
161 public function documentation() {
162 $response = new TrustedRedirectResponse("https://api.drupal.org/api/drupal/8");
170 public function runCron() {
172 drupal_set_message($this->t('Cron ran successfully.'));
173 return new RedirectResponse($this->reload_page());
177 * Clear the rendered cache.
179 public function cacheRender() {
180 $this->cacheRender->invalidateAll();
181 drupal_set_message($this->t('Render cache cleared.'));
182 return new RedirectResponse($this->reload_page());