5 * Controls the placement of blocks from all pages.
8 use Drupal\Core\Routing\RouteMatchInterface;
12 * Implements hook_help().
14 function block_place_help($route_name, RouteMatchInterface $route_match) {
15 switch ($route_name) {
16 case 'help.page.block_place':
17 $output = '<h3>' . t('About') . '</h3>';
18 $output .= '<p>' . t('The Place Blocks module allows you to place blocks from every page. For more information, see the <a href=":blocks-documentation">online documentation for the Place Blocks module</a>.', [':blocks-documentation' => 'https://www.drupal.org/documentation/modules/block_place/']) . '</p>';
19 $output .= '<h3>' . t('Uses') . '</h3>';
20 $output .= '<p>' . t('Block placement is specific to each theme on your site. This module allows you to place blocks in the context of your content pages.') . '</p>';
26 * Implements hook_toolbar().
28 function block_place_toolbar() {
29 // Link to the current page with a query parameter.
30 $query = \Drupal::request()->query->all();
34 if (isset($query['block-place'])) {
35 $status_class = 'active';
36 $wrapper_class = 'is-active';
37 $description = t('Exit Place block mode.');
38 unset($query['block-place']);
39 unset($query['destination']);
42 $status_class = 'inactive';
43 $description = t('Show regions to Place blocks.');
44 $query['block-place'] = '1';
45 // Setting destination is both a work-around for the toolbar "Back to site"
46 // link in escapeAdmin.js and used for the destination after picking a
48 $query['destination'] = Url::fromRoute('<current>')->toString();
51 // Remove on Admin routes.
52 $admin_route = \Drupal::service('router.admin_context')->isAdminRoute();
53 // Remove on Block Demo page.
54 $admin_demo = \Drupal::routeMatch()->getRouteName() === 'block.admin_demo';
55 $access = (\Drupal::currentUser()->hasPermission('administer blocks') && !$admin_route && !$admin_demo);
57 // The 'Place Block' tab is a simple link, with no corresponding tray.
58 $items['block_place'] = [
60 'contexts' => ['user.permissions', 'url.query_args'],
62 '#type' => 'toolbar_item',
66 '#title' => t('Place block'),
67 '#url' => Url::fromRoute('<current>', [], ['query' => $query]),
69 'title' => $description,
70 'class' => ['toolbar-icon', 'toolbar-icon-place-block-' . $status_class],
73 '#wrapper_attributes' => [
74 'class' => ['toolbar-tab', 'block-place-toolbar-tab', $wrapper_class],
79 'block_place/drupal.block_place.icons',