Commit 24c3330b authored by matio89's avatar matio89

add admin_toolbar & admin_toolbar_tools

parent e86cb581
name = Admin toolbar
toolbar.tree:
version: VERSION
css:
theme:
css/admin.toolbar.css: {}
\ No newline at end of file
<?php
/**
* Implements hook_toolbar().
*/
function admin_toolbar_toolbar() {
$items = array();
$items['admin_toolbar'] = array(
'#type' => 'toolbar_item',
'#attached' => array(
'library' => array(
'admin_toolbar/toolbar.tree',
),
),
);
return $items;
}
/**
* Implements hook_toolbar_alter().
*/
function admin_toolbar_toolbar_alter(&$items) {
// To conserve bandwidth, we only include the top-level links in the HTML.
// The subtrees are fetched through a JSONP script that is generated at the
// toolbar_subtrees route. We provide the JavaScript requesting that JSONP
// script here with the hash parameter that is needed for that route.
// @see toolbar_subtrees_jsonp()
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
$subtrees_attached['drupalSettings']['toolbar'] = [
'subtreesHash' => admin_toolbar_get_subtrees_hash($langcode),
'langcode' => $langcode,
];
// a toolbar tray. The tray contains the full administrative menu of the site.
$items['administration'] = array(
'#type' => 'toolbar_item',
'tab' => array(
'#type' => 'link',
'#title' => t('Manage'),
'#url' => \Drupal\Core\Url::fromRoute('system.admin'),
'#attributes' => array(
'title' => t('Admin menu'),
'class' => array('toolbar-icon', 'toolbar-icon-menu'),
// A data attribute that indicates to the client to defer loading of
// the admin menu subtrees until this tab is activated. Admin menu
// subtrees will not render to the DOM if this attribute is removed.
// The value of the attribute is intentionally left blank. Only the
// presence of the attribute is necessary.
'data-drupal-subtrees' => '',
),
),
'tray' => array(
'#heading' => t('Administration menu'),
'#attached' => $subtrees_attached,
'toolbar_administration' => array(
'#pre_render' => array(
'toolbar_prerender_admin_toolbar_administration_tray',
),
'#type' => 'container',
'#attributes' => array(
'class' => array('toolbar-menu-administration'),
),
),
),
'#weight' => -15,
);
return $items;
}
/**
* Renders the toolbar's administration tray.
*
* @param array $element
* A renderable array.
*
* @return array
* The updated renderable array.
*
* @see drupal_render()
*/
function toolbar_prerender_admin_toolbar_administration_tray(array $element) {
$menu_tree = \Drupal::menuTree();
// Render the top-level administration menu links.
$parameters = new \Drupal\Core\Menu\MenuTreeParameters();
$parameters->setRoot('system.admin')->excludeRoot()->setMaxDepth(3);
$tree = $menu_tree->load(NULL, $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
array('callable' => 'toolbar_menu_navigation_links'),
);
$tree = $menu_tree->transform($tree, $manipulators);
$element['administration_menu'] = $menu_tree->build($tree);
return $element;
}
/**
* Returns the hash of the per-user rendered toolbar subtrees.
*
* @param string $langcode
* The langcode of the current request.
*
* @return string
* The hash of the admin_menu subtrees.
*/
function admin_toolbar_get_subtrees_hash($langcode) {
$uid = \Drupal::currentUser()->id();
$cid = _toolbar_get_user_cid($uid, $langcode);
$subtrees = toolbar_get_rendered_subtrees();
$hash = \Drupal\Component\Utility\Crypt::hashBase64(serialize($subtrees));
$role_list_cache_tags = \Drupal::entityManager()->getDefinition('user_role')->getListCacheTags();
\Drupal::cache('toolbar')->set($cid, $hash, \Drupal\Core\Cache\Cache::PERMANENT, \Drupal\Core\Cache\Cache::mergeTags(array('user:' . $uid, 'locale', 'config:system.menu.admin'), $role_list_cache_tags));
return $hash;
}
name: Admin Toolbar Tools
core: 8.x
description: Admin Toolbar Tools lets to add more fonctionalities in the admin menu.
package: Administration
type: module
version: 1.0
dependencies:
- admin_toolbar
\ No newline at end of file
toolbar.icon:
version: VERSION
css:
theme:
css/tools.css: {}
\ No newline at end of file
admin_toolbar_tools.help:
title: Tools
description: Admin toolbar tools
route_name: admin_toolbar_tools.help
weight: -15
parent: system.admin
system.admin_index:
title: Index
description: Admin toolbar tools
weight: -10
route_name: system.admin_index
parent: admin_toolbar_tools.help
admin_toolbar_tools.flush:
title: Flush all caches
route_name: admin_toolbar_tools.flush
weight: -9
parent: admin_toolbar_tools.help
admin_toolbar_tools.cssjs:
title: CSS and Javascript
route_name: admin_toolbar_tools.cssjs
parent: admin_toolbar_tools.flush
admin_toolbar_tools.plugin:
title: Plugins
route_name: admin_toolbar_tools.plugin
parent: admin_toolbar_tools.flush
admin_toolbar_tools.flush_static:
title: Static caches
route_name: admin_toolbar_tools.flush_static
parent: admin_toolbar_tools.flush
system.run_cron:
title: Run cron
weight: -8
route_name: system.run_cron
parent: admin_toolbar_tools.help
system.db_update:
title: Run Updates
weight: -7
route_name: system.db_update
parent: admin_toolbar_tools.help
admin_toolbar_tools.drupalorg:
title: Drupal.org
weight: -6
route_name: admin_toolbar_tools.drupalorg
parent: admin_toolbar_tools.help
admin_toolbar_tools.listchanges:
title: List changes D8
weight: -6
route_name: admin_toolbar_tools.listchanges
parent: admin_toolbar_tools.drupalorg
admin_toolbar_tools.doc:
title: Documentation D8
weight: -5
route_name: admin_toolbar_tools.doc
parent: admin_toolbar_tools.drupalorg
<?php
use Drupal\Core\Routing\RouteMatchInterface;
// add css and icon in toolbar
/**
* Implements hook_toolbar().
*/
function admin_toolbar_tools_toolbar() {
$items = array();
$items['admin_toolbar_tools'] = array(
'#type' => 'toolbar_item',
'#attributes' => array(
'class' => array('toolbar-icon', 'toolbar-icon-admin-toolbar-tools-help'),
),
'#attached' => array(
'library' => array(
'admin_toolbar_tools/toolbar.icon',
),
),
);
return $items;
}
/**
* Implements hook_help().
*/
function admin_toolbar_tools_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.admin_toolbar_tools':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Admin Toolbar Tools module allows you to to add more fonctionalities to the toolbar like flush caches, runnig cron.') . '</p>';
return $output;
}
}
\ No newline at end of file
admin_toolbar_tools.help:
path: '/admin/tools'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::home'
_title: 'Toolbar tools'
requirements:
_permission: 'access administration pages'
admin_toolbar_tools.flush:
path: '/admin/flush'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushAll'
_title: 'Flush all caches'
requirements:
_permission: 'access administration pages'
admin_toolbar_tools.cssjs:
path: '/admin/flush/cssjs'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flush_js_css'
_title: 'Flush Css and Javascript'
requirements:
_permission: 'access administration pages'
admin_toolbar_tools.plugin:
path: '/admin/flush/plugin'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flush_plugins'
_title: 'Plugin'
requirements:
_permission: 'access administration pages'
admin_toolbar_tools.flush_static:
path: '/admin/flush/static-caches'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flush_static'
_title: 'static caches'
requirements:
_permission: 'access administration pages'
admin_toolbar_tools.drupalorg:
path: '/admin/drupal8'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::drupal_org'
_title: 'Drupal'
requirements:
_permission: 'access administration pages'
admin_toolbar_tools.listchanges:
path: '/admin/drupal/list-changes'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::list_changes'
_title: 'List changes'
requirements:
_permission: 'access administration pages'
admin_toolbar_tools.doc:
path: '/admin/drupal/documentation'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::documentation'
_title: 'Documentation D8'
requirements:
_permission: 'access administration pages'
\ No newline at end of file
.toolbar-icon-admin-toolbar-tools-help {
text-indent: -9999px;
}
.toolbar-icon-admin-toolbar-tools-help:before {
background-image: url(../misc/icons/ffffff/d8-item.svg);
padding-bottom: 0;
padding-left: 4px;
padding-right: 8px;
padding-top: 2px;
}
.toolbar-icon-admin-toolbar-tools-help:active:before,
.toolbar-icon-admin-toolbar-tools-help.active:before {
background-image: url(../misc/icons/ffffff/d8-item.svg);
}
This diff is collapsed.
<?php
/**
* @file
* Contains \Drupal\admin_toolbar_tools\Controller\ToolbarController.
*
*/
namespace Drupal\admin_toolbar_tools\Controller;
//Use the necessary classes
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Class ToolbarController
* @package Drupal\admin_toolbar_tools\Controller
*/
class ToolbarController extends ControllerBase {
//This function display the tools in the menu.
public function home() {
return new RedirectResponse('/');
}
//This function flush all caches.
public function flushAll() {
drupal_flush_all_caches();
drupal_set_message(t('All cache cleared.'));
return new RedirectResponse('/');
}
//This function flush css and javascript caches.
public function flush_js_css() {
\Drupal::state()
->set('system.css_js_query_string', base_convert(REQUEST_TIME, 10, 36));
drupal_set_message(t('CSS and JavaScript cache cleared.'));
return new RedirectResponse('/');
}
//This function flush plugins caches.
public function flush_plugins() {
// Clear all plugin caches.
\Drupal::service('plugin.cache_clearer')->clearCachedDefinitions();
drupal_set_message(t('Plugin cache cleared.'));
return new RedirectResponse('/');
}
// Reset all static caches.
public function flush_static() {
drupal_static_reset();
drupal_set_message(t('All static caches cleared.'));
return new RedirectResponse('/');
}
// this function allow to access in documentation via admin_toolbar module
public function drupal_org() {
$response = new RedirectResponse("https://www.drupal.org");
$response->send();
return $response;
}
// this function allow to access in documentation(list changes of the different versions of drupal core) via admin_toolbar module.
public function list_changes() {
$response = new RedirectResponse("https://www.drupal.org/list-changes");
$response->send();
return $response;
}
//this function allow to add
public function documentation() {
$response = new RedirectResponse("https://api.drupal.org/api/drupal/8");
$response->send();
return $response;
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment