Backup of db before drupal security update
[yaffs-website] / web / core / modules / block_place / block_place.module
1 <?php
2
3 /**
4  * @file
5  * Controls the placement of blocks from all pages.
6  */
7
8 use Drupal\Core\Routing\RouteMatchInterface;
9 use Drupal\Core\Url;
10
11 /**
12  * Implements hook_help().
13  */
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>';
21       return $output;
22   }
23 }
24
25 /**
26  * Implements hook_toolbar().
27  */
28 function block_place_toolbar() {
29   // Link to the current page with a query parameter.
30   $query = \Drupal::request()->query->all();
31   $wrapper_class = '';
32   $status_class = '';
33   $description = '';
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']);
40   }
41   else {
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
47     // block.
48     $query['destination'] = Url::fromRoute('<current>')->toString();
49   }
50
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);
56
57   // The 'Place Block' tab is a simple link, with no corresponding tray.
58   $items['block_place'] = [
59     '#cache' => [
60       'contexts' => ['user.permissions', 'url.query_args'],
61     ],
62     '#type' => 'toolbar_item',
63     'tab' => [
64       '#access' => $access,
65       '#type' => 'link',
66       '#title' => t('Place block'),
67       '#url' => Url::fromRoute('<current>', [], ['query' => $query]),
68       '#attributes' => [
69         'title' => $description,
70         'class' => ['toolbar-icon', 'toolbar-icon-place-block-' . $status_class],
71       ],
72     ],
73     '#wrapper_attributes' => [
74       'class' => ['toolbar-tab', 'block-place-toolbar-tab', $wrapper_class],
75     ],
76     '#weight' => 100,
77     '#attached' => [
78       'library' => [
79         'block_place/drupal.block_place.icons',
80       ],
81    ],
82   ];
83   return $items;
84 }