block_place_toolbar()
Implements hook_toolbar().
File
- core/modules/block_place/block_place.module, line 28
- Controls the placement of blocks from all pages.
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 block_place_toolbar() { // Link to the current page with a query parameter. $query = \Drupal::request()->query->all(); $wrapper_class = '' ; $status_class = '' ; $description = '' ; if (isset( $query [ 'block-place' ])) { $status_class = 'active' ; $wrapper_class = 'is-active' ; $description = t( 'Exit Place block mode.' ); unset( $query [ 'block-place' ]); unset( $query [ 'destination' ]); } else { $status_class = 'inactive' ; $description = t( 'Show regions to Place blocks.' ); $query [ 'block-place' ] = '1' ; // Setting destination is both a work-around for the toolbar "Back to site" // link in escapeAdmin.js and used for the destination after picking a // block. $query [ 'destination' ] = Url::fromRoute( '<current>' )->toString(); } // Remove on Admin routes. $admin_route = \Drupal::service( 'router.admin_context' )->isAdminRoute(); // Remove on Block Demo page. $admin_demo = \Drupal::routeMatch()->getRouteName() === 'block.admin_demo' ; $access = (\Drupal::currentUser()->hasPermission( 'administer blocks' ) && ! $admin_route && ! $admin_demo ); // The 'Place Block' tab is a simple link, with no corresponding tray. $items [ 'block_place' ] = [ '#cache' => [ 'contexts' => [ 'user.permissions' , 'url.query_args' ], ], '#type' => 'toolbar_item' , 'tab' => [ '#access' => $access , '#type' => 'link' , '#title' => t( 'Place block' ), '#url' => Url::fromRoute( '<current>' , [], [ 'query' => $query ]), '#attributes' => [ 'title' => $description , 'class' => [ 'toolbar-icon' , 'toolbar-icon-place-block-' . $status_class ], ], ], '#wrapper_attributes' => [ 'class' => [ 'toolbar-tab' , 'block-place-toolbar-tab' , $wrapper_class ], ], '#weight' => 100, '#attached' => [ 'library' => [ 'block_place/drupal.block_place.icons' , ], ], ]; return $items ; } |
Please login to continue.