Skip to content
Snippets Groups Projects
Commit 28507c2a authored by Mohamed Anis Taktak's avatar Mohamed Anis Taktak
Browse files

add new fonctionalities

parent e2e80e49
No related branches found
No related tags found
No related merge requests found
name = Admin toolbar
...@@ -80,7 +80,7 @@ function toolbar_prerender_admin_toolbar_administration_tray(array $element) { ...@@ -80,7 +80,7 @@ function toolbar_prerender_admin_toolbar_administration_tray(array $element) {
$menu_tree = \Drupal::menuTree(); $menu_tree = \Drupal::menuTree();
// Render the top-level administration menu links. // Render the top-level administration menu links.
$parameters = new \Drupal\Core\Menu\MenuTreeParameters(); $parameters = new \Drupal\Core\Menu\MenuTreeParameters();
$parameters->setRoot('system.admin')->excludeRoot()->setMaxDepth(3); $parameters->setRoot('system.admin')->excludeRoot()->setMaxDepth(4);
$tree = $menu_tree->load(NULL, $parameters); $tree = $menu_tree->load(NULL, $parameters);
$manipulators = array( $manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:checkAccess'),
......
...@@ -27,6 +27,10 @@ admin_toolbar_tools.flush_static: ...@@ -27,6 +27,10 @@ admin_toolbar_tools.flush_static:
title: Static caches title: Static caches
route_name: admin_toolbar_tools.flush_static route_name: admin_toolbar_tools.flush_static
parent: admin_toolbar_tools.flush parent: admin_toolbar_tools.flush
admin_toolbar_tools.flush_menu:
title: Menu
route_name: admin_toolbar_tools.flush_menu
parent: admin_toolbar_tools.flush
system.run_cron: system.run_cron:
title: Run cron title: Run cron
weight: -8 weight: -8
...@@ -57,3 +61,91 @@ admin_development: ...@@ -57,3 +61,91 @@ admin_development:
weight: -8 weight: -8
route_name: admin_development route_name: admin_development
parent: admin_toolbar_tools.help parent: admin_toolbar_tools.help
update.module_update:
title: Update
route_name: update.module_update
parent: system.modules_list
weight: -1
system.modules_uninstall:
title: Uninstall
route_name: system.modules_uninstall
parent: system.modules_list
weight: -2
update.module_install:
title: Install new module
route_name: update.module_install
parent: system.modules_list
weight: -3
#add menu to people
user.admin_create:
title: Add user
route_name: user.admin_create
parent: entity.user.collection
weight: -5
user.admin_permissions:
title: Permissions
route_name: user.admin_permissions
parent: entity.user.collection
weight: -4
user.admin_create:
title: Add user
route_name: user.admin_create
parent: entity.user.collection
weight: -3
entity.user_role.collection:
title: Roles
route_name: entity.user_role.collection
parent: entity.user.collection
weight: -2
node.add_page:
parent: system.admin_content
node.type_add:
title: Add content type
route_name: node.type_add
parent: entity.node_type.collection
weight: -5
entity.taxonomy_vocabulary.add_form:
title: Add vocabulary
route_name: entity.taxonomy_vocabulary.add_form
parent: entity.taxonomy_vocabulary.collection
weight: -5
entity.comment_type.add_form:
title: Add comment type
route_name: entity.comment_type.add_form
parent: entity.comment_type.collection
weight: -5
entity.menu.add_form:
title: Add menu
route_name: entity.menu.add_form
parent: entity.menu.collection
weight: -50
block_content.add_page:
title: Add custom block
route_name: block_content.add_page
parent: block.admin_display
weight: -5
entity.block_content.collection:
title: Custom block library
route_name: entity.block_content.collection
parent: block.admin_display
weight: -4
entity.block_content_type.collection:
title: Types
route_name: entity.block_content_type.collection
parent: block.admin_display
weight: -3
block_content.type_add:
title: Add
route_name: block_content.type_add
parent: entity.block_content_type.collection
weight: -5
contact.form_add:
title: Add contact form
route_name: contact.form_add
parent: entity.contact_form.collection
weight: -5
#links comments
comment.admin_approval:
title: Unapproved comments
route_name: comment.admin_approval
parent: comment.admin
\ No newline at end of file
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
// add css and icon in toolbar // add css and icon in toolbar
/** /**
* Implements hook_toolbar(). * Implements hook_toolbar().
...@@ -40,6 +39,7 @@ function admin_toolbar_tools_help($route_name, RouteMatchInterface $route_match) ...@@ -40,6 +39,7 @@ function admin_toolbar_tools_help($route_name, RouteMatchInterface $route_match)
* Implements hook_menu_links_discovered_alter(). * Implements hook_menu_links_discovered_alter().
*/ */
function admin_toolbar_tools_menu_links_discovered_alter(&$links) { function admin_toolbar_tools_menu_links_discovered_alter(&$links) {
if (\Drupal::moduleHandler()->moduleExists('devel')) { if (\Drupal::moduleHandler()->moduleExists('devel')) {
$links['devel.admin_settings'] = array( $links['devel.admin_settings'] = array(
'title' => 'Devel settings', 'title' => 'Devel settings',
...@@ -101,10 +101,240 @@ function admin_toolbar_tools_menu_links_discovered_alter(&$links) { ...@@ -101,10 +101,240 @@ function admin_toolbar_tools_menu_links_discovered_alter(&$links) {
'route_name' => 'devel.run_cron', 'route_name' => 'devel.run_cron',
'parent' => 'admin_development' 'parent' => 'admin_development'
); );
}
// Adding links to /admin/structure/menu
$menu_titles = menu_ui_get_menus();
foreach ($menu_titles as $key => $value) {
$links['entity.menu.edit_form' . '_' . $key] = array(
'title' => $value,
'route_name' => 'entity.menu.edit_form',
'parent' => 'entity.menu.collection',
'route_parameters' => array(
'menu' => $key
)
);
}
// adding /node/add/{node_type};
$node_types = node_type_get_names();
foreach ($node_types as $machine_name_node_type => $name_node_type) {
$links['node.add' . $machine_name_node_type] = array(
'title' => $name_node_type,
'route_name' => 'node.add',
'parent' => 'node.add_page',
'route_parameters' => array(
'node_type' => $machine_name_node_type
)
);
$links['node.type' . $machine_name_node_type] = array(
'title' => $name_node_type,
'route_name' => 'entity.node_type.edit_form',
'parent' => 'entity.node_type.collection',
'route_parameters' => array(
'node_type' => $machine_name_node_type
)
);
$links['node.delete.type' . $machine_name_node_type] = array(
'title' => $name_node_type,
'route_name' => 'entity.node_type.edit_form',
'parent' => 'node_type.edit',
'route_parameters' => array(
'node_type' => $machine_name_node_type
)
);
}
// add taxonomy links
$taxo_vocab = taxonomy_get_vocabulary();
foreach ($taxo_vocab as $machine_name_taxo_vocab => $value_taxo_vocab) {
$links['entity.taxonomy_vocabulary.edit_form' . $machine_name_taxo_vocab] = array(
'title' => $value_taxo_vocab,
'route_name' => 'entity.taxonomy_vocabulary.edit_form',
'parent' => 'entity.taxonomy_vocabulary.collection',
'route_parameters' => array(
'taxonomy_vocabulary' => $machine_name_taxo_vocab
)
);
}
// add comments links
$comments = comments_get_names();
foreach ($comments as $machine_name_comments => $name_comments) {
$links['entity.comment_type.edit_form' . $machine_name_comments] = array(
'title' => $name_comments,
'route_name' => 'entity.comment_type.edit_form',
'parent' => 'entity.comment_type.collection',
'route_parameters' => array(
'comment_type' => $machine_name_comments
)
);
}
//adding links /admin/structure/contact
$contacts_form = contact_message_get_names();
foreach($contacts_form as $machine_name_contact_form => $name_contact_form){
$links['entity.comment_type.edit_form' . $machine_name_contact_form] = array(
'title' => $name_contact_form,
'route_name' => 'entity.contact_form.edit_form',
'parent' => 'entity.contact_form.collection',
'route_parameters' => array(
'contact_form' => $machine_name_contact_form
)
);
}
//addling links to /admin/structure/people
$prefix_people_child = "/admin/people";
$parents = delete_child_like_parent($prefix_people_child);
$user_roles = extract_label_id_user_role();
foreach ($parents as $route_name_parents => $values_parents) {
foreach ($values_parents as $keyChild => $valueChild) {
if (is_numeric($keyChild)) {
foreach ($user_roles as $id_user_role => $label_user_role) {
$links[$keyChild . $id_user_role] = array(
'title' => $label_user_role,
'route_name' => $valueChild,
'parent' => $route_name_parents,
'route_parameters' => array(
'user_role' => $id_user_role
)
);
}
}
else {
$links[$keyChild . $valueChild] = array(
'title' => "Add role",
'route_name' => $valueChild,
'parent' => $route_name_parents,
'weight' => -5
);
}
}
} }
$links['node.add_page']['parent'] = 'system.admin_content';
return $links; return $links;
}
// Get machine name and label of entity (bundle: taxonomy vocabulary).
function taxonomy_get_vocabulary() {
return array_map(function ($bundle_info) {
return $bundle_info['label'];
}, \Drupal::entityManager()->getBundleInfo('taxonomy_term'));
}
// Get machine name and label of entity (bundle: contact message).
function contact_message_get_names(){
return array_map(function ($bundle_info) {
return $bundle_info['label'];
}, \Drupal::entityManager()->getBundleInfo('contact_message'));
}
// Get machine name and label of entity (bundle: comments).
function comments_get_names() {
return array_map(function ($bundle_info) {
return $bundle_info['label'];
}, \Drupal::entityManager()->getBundleInfo('comment'));
}
// Get machine name and label of entity (bundle: block).
function block_get_names() {
return array_map(function ($bundle_info) {
return $bundle_info['label'];
}, \Drupal::entityManager()->getBundleInfo('block_content'));
}
// Extract label and id of all users role.
function extract_label_id_user_role() {
$roles_obj = user_roles();
$roles = array();
foreach ($roles_obj as $role) {
$roles[$role->id()] = $role->label();
}
return $roles;
}
// Select all path
function db_select_router_path($prefix, $display_placeholder_path = FALSE) {
$results = db_select_router($prefix);
foreach ($results as $key => $value) {
$key = $value->path;
if ($display_placeholder_path == TRUE) {
if (!(substr_count($value->path, "{") != 0)) {
$list[$key] = $value->name;
}
}
else {
$list[$key] = $value->name;
}
}
asort($list);
return $list;
}
// Select all route from router table.
function db_select_router_route($prefix, $display_placeholder_path = FALSE) {
$results = db_select_router($prefix);
foreach ($results as $key => $value) {
$key = $value->name;
if ($display_placeholder_path == TRUE) {
if (!(substr_count($value->path, "{") != 0)) {
$list[$key] = $value->path;
}
}
else {
$list[$key] = $value->path;
}
}
asort($list);
return $list;
}
// Select table router from db and filter result with a prefix.
function db_select_router($prefix) {
return db_select('router', 't')
->fields('t', array('path', 'name', 'number_parts'))
->condition('path', db_like($prefix) . '%', 'LIKE')
->execute();
}
// Retrieve the last element of the path = title of the page.
function last_element_path($keys_paths) {
$titles = array();
foreach ($keys_paths as $keys_path) {
$titles[] = ucfirst(end(explode("/", $keys_path)));
}
return $titles;
} }
// Extract child and parent route from prefix and parents
function extract_repeated_path_in_array($prefix) {
$parents_path = array_keys(db_select_router_path($prefix . "/"));
$parents_route = array_values(db_select_router_path($prefix . "/"));
$routes = array_values(db_select_router_path($prefix));
$paths = array_keys(db_select_router_path($prefix));
$child = array();
$groupped_child = array();
for ($j = 0; $j < count($parents_path); $j++) {
unset($child);
for ($i = 0; $i < count($paths); $i++) {
if (substr_count($paths[$i], $parents_path[$j]) != 0) {
if (!(substr_count($paths[$i], '{') != 0)) {
$child["without"] = $routes[$i];
}
else {
$child[$i] = $routes[$i];
}
}
}
if (count($child) > 1) {
$groupped_child[$parents_route[$j]] = $child;
}
}
return $groupped_child;
}
// Delete all child which have the same route with parent.
function delete_child_like_parent($prefix) {
$list_parents = extract_repeated_path_in_array($prefix);
$list_changed = $list_parents;
foreach ($list_changed as $list_parent => $valueParent) {
foreach ($valueParent as $childKey => $childValue) {
if ($list_parent == $childValue) {
unset($list_changed[$list_parent][$childKey]);
}
}
}
return $list_changed;
}
...@@ -30,7 +30,14 @@ admin_toolbar_tools.flush_static: ...@@ -30,7 +30,14 @@ admin_toolbar_tools.flush_static:
path: '/admin/flush/static-caches' path: '/admin/flush/static-caches'
defaults: defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flush_static' _controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flush_static'
_title: 'static caches' _title: 'Static caches'
requirements:
_permission: 'access administration pages'
admin_toolbar_tools.flush_menu:
path: '/admin/flush/menu'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flush_menu'
_title: 'Menu'
requirements: requirements:
_permission: 'access administration pages' _permission: 'access administration pages'
admin_toolbar_tools.drupalorg: admin_toolbar_tools.drupalorg:
......
...@@ -11,28 +11,34 @@ namespace Drupal\admin_toolbar_tools\Controller; ...@@ -11,28 +11,34 @@ namespace Drupal\admin_toolbar_tools\Controller;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
/** /**
* Class ToolbarController * Class ToolbarController
* @package Drupal\admin_toolbar_tools\Controller * @package Drupal\admin_toolbar_tools\Controller
*/ */
class ToolbarController extends ControllerBase { class ToolbarController extends ControllerBase {
//This function display the tools in the menu //Redirect to home.
public function home() { public function home() {
return new RedirectResponse('/'); return new RedirectResponse('/');
} }
//Reload the previous page.
public function reload_page() { public function reload_page() {
$request = \Drupal::request(); $request = \Drupal::request();
return $request->server->get('HTTP_REFERER'); return $request->server->get('HTTP_REFERER');
} }
//Flush all caches.
public function flushAll() { public function flushAll() {
drupal_flush_all_caches(); drupal_flush_all_caches();
drupal_set_message(t('All cache cleared.')); drupal_set_message(t('All cache cleared.'));
return new RedirectResponse($this->reload_page()); return new RedirectResponse($this->reload_page());
} }
public function testdb() {
dpm(contact_message_get_names());
}
//This function flush css and javascript caches. //This function flush css and javascript caches.
public function flush_js_css() { public function flush_js_css() {
\Drupal::state() \Drupal::state()
...@@ -40,6 +46,7 @@ class ToolbarController extends ControllerBase { ...@@ -40,6 +46,7 @@ class ToolbarController extends ControllerBase {
drupal_set_message(t('CSS and JavaScript cache cleared.')); drupal_set_message(t('CSS and JavaScript cache cleared.'));
return new RedirectResponse($this->reload_page()); return new RedirectResponse($this->reload_page());
} }
//This function flush plugins caches. //This function flush plugins caches.
public function flush_plugins() { public function flush_plugins() {
// Clear all plugin caches. // Clear all plugin caches.
...@@ -47,6 +54,7 @@ class ToolbarController extends ControllerBase { ...@@ -47,6 +54,7 @@ class ToolbarController extends ControllerBase {
drupal_set_message(t('Plugin cache cleared.')); drupal_set_message(t('Plugin cache cleared.'));
return new RedirectResponse($this->reload_page()); return new RedirectResponse($this->reload_page());
} }
// Reset all static caches. // Reset all static caches.
public function flush_static() { public function flush_static() {
drupal_static_reset(); drupal_static_reset();
...@@ -54,6 +62,13 @@ class ToolbarController extends ControllerBase { ...@@ -54,6 +62,13 @@ class ToolbarController extends ControllerBase {
return new RedirectResponse($this->reload_page()); return new RedirectResponse($this->reload_page());
} }
// Clears all cached menu data.
public function flush_menu() {
menu_cache_clear_all();
drupal_set_message(t('All cached menu data cleared.'));
return new RedirectResponse($this->reload_page());
}
// this function allow to access in documentation via admin_toolbar module // this function allow to access in documentation via admin_toolbar module
public function drupal_org() { public function drupal_org() {
$response = new RedirectResponse("https://www.drupal.org"); $response = new RedirectResponse("https://www.drupal.org");
...@@ -61,6 +76,11 @@ class ToolbarController extends ControllerBase { ...@@ -61,6 +76,11 @@ class ToolbarController extends ControllerBase {
return $response; return $response;
} }
//This function display the administration link Development
public function development() {
return new RedirectResponse('/admin/structure/menu/');
}
// this function allow to access in documentation(list changes of the different versions of drupal core) via admin_toolbar module. // this function allow to access in documentation(list changes of the different versions of drupal core) via admin_toolbar module.
public function list_changes() { public function list_changes() {
$response = new RedirectResponse("https://www.drupal.org/list-changes"); $response = new RedirectResponse("https://www.drupal.org/list-changes");
...@@ -74,9 +94,6 @@ class ToolbarController extends ControllerBase { ...@@ -74,9 +94,6 @@ class ToolbarController extends ControllerBase {
$response->send(); $response->send();
return $response; return $response;
} }
//This function display the administration link Development
public function development(){
return new RedirectResponse('/admin/structure/menu/');
}
} }
\ No newline at end of file
...@@ -41,3 +41,9 @@ ...@@ -41,3 +41,9 @@
left: 160px; left: 160px;
width: 160px; width: 160px;
} }
.toolbar .toolbar-tray-vertical li.open > ul.menu {
display: none;
}
.toolbar .toolbar-tray-vertical li.open > ul.menu.clearfix {
display: block;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment