system_get_module_admin_tasks($module, array $info)
Generate a list of tasks offered by a specified module.
Parameters
string $module: Module name.
array $info: The module's information, as provided by system_get_info().
Return value
array An array of task links.
File
- core/modules/system/system.module, line 1211
- Configuration system that lets administrators modify the workings of the site.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | function system_get_module_admin_tasks( $module , array $info ) { $tree = &drupal_static( __FUNCTION__ ); $menu_tree = \Drupal::menuTree(); if (!isset( $tree )) { $parameters = new MenuTreeParameters(); $parameters ->setRoot( 'system.admin' )->excludeRoot()->onlyEnabledLinks(); $tree = $menu_tree ->load( 'system.admin' , $parameters ); $manipulators = array ( array ( 'callable' => 'menu.default_tree_manipulators:checkAccess' ), array ( 'callable' => 'menu.default_tree_manipulators:generateIndexAndSort' ), array ( 'callable' => 'menu.default_tree_manipulators:flatten' ), ); $tree = $menu_tree ->transform( $tree , $manipulators ); } $admin_tasks = array (); foreach ( $tree as $element ) { if (! $element ->access->isAllowed()) { // @todo Bubble cacheability metadata of both accessible and inaccessible // links. Currently made impossible by the way admin tasks are rendered. continue ; } $link = $element ->link; if ( $link ->getProvider() != $module ) { continue ; } $admin_tasks [] = array ( 'title' => $link ->getTitle(), 'description' => $link ->getDescription(), 'url' => $link ->getUrlObject(), ); } // Append link for permissions. /** @var \Drupal\user\PermissionHandlerInterface $permission_handler */ $permission_handler = \Drupal::service( 'user.permissions' ); if ( $permission_handler ->moduleProvidesPermissions( $module )) { /** @var \Drupal\Core\Access\AccessManagerInterface $access_manager */ $access_manager = \Drupal::service( 'access_manager' ); if ( $access_manager ->checkNamedRoute( 'user.admin_permissions' , array (), \Drupal::currentUser())) { /** @var \Drupal\Core\Url $url */ $url = new Url( 'user.admin_permissions' ); $url ->setOption( 'fragment' , 'module-' . $module ); $admin_tasks [ "user.admin_permissions.$module" ] = array ( 'title' => t( 'Configure @module permissions' , array ( '@module' => $info [ 'name' ])), 'description' => '' , 'url' => $url , ); } } return $admin_tasks ; } |
Please login to continue.