forked from drupal/drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutside_in.module
More file actions
138 lines (124 loc) · 5.29 KB
/
outside_in.module
File metadata and controls
138 lines (124 loc) · 5.29 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* @file
* Allows configuring blocks and other configuration from the site front-end.
*/
use Drupal\Core\Asset\AttachedAssetsInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\block\Form\BlockEntityOffCanvasForm;
use Drupal\system\Form\SystemBrandingOffCanvasForm;
use Drupal\system\Form\SystemMenuOffCanvasForm;
/**
* Implements hook_help().
*/
function outside_in_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.outside_in':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Settings Tray module provides an \'edit mode\' in which clicking on a block opens a slide-out tray which allows configuration to be altered without leaving the page.For more information, see the <a href=":outside-in-documentation">online documentation for the Settings Tray module</a>.', [':outside-in-documentation' => 'https://www.drupal.org/documentation/modules/outside_in']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Editing blocks on the same page in the slide-out tray') . '</dt>';
$output .= '</dl>';
return ['#markup' => $output];
}
}
/**
* Implements hook_contextual_links_view_alter().
*
* Change Configure Blocks into off_canvas links.
*/
function outside_in_contextual_links_view_alter(&$element, $items) {
if (isset($element['#links']['outside-inblock-configure'])) {
// Place outside_in link first.
$outside_in_link = $element['#links']['outside-inblock-configure'];
unset($element['#links']['outside-inblock-configure']);
$element['#links'] = ['outside-inblock-configure' => $outside_in_link] + $element['#links'];
$element['#links']['outside-inblock-configure']['attributes'] = [
'class' => ['use-ajax'],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
'data-outside-in-edit' => TRUE,
];
// If this is content block change title to avoid duplicate "Quick Edit".
if (isset($element['#links']['block-contentblock-edit'])) {
$element['#links']['outside-inblock-configure']['title'] = t('Quick edit settings');
}
$element['#attached']['library'][] = 'core/drupal.dialog.off_canvas';
}
}
/**
* Implements hook_block_view_alter().
*/
function outside_in_block_view_alter(array &$build) {
// Force a new 'data-contextual-id' attribute on blocks when this module is
// enabled so as not to reuse stale data cached client-side.
// @todo Remove when https://www.drupal.org/node/2773591 is fixed.
$build['#contextual_links']['outside_in'] = [
'route_parameters' => [],
];
}
/**
* Implements hook_preprocess_HOOK() for block templates.
*/
function outside_in_preprocess_block(&$variables) {
// The main system block does not contain the block contextual links.
if ($variables['plugin_id'] !== 'system_main_block') {
// Add class and attributes to all blocks to allow Javascript to target.
$variables['attributes']['class'][] = 'outside-in-editable';
$variables['attributes']['data-drupal-outsidein'] = 'editable';
}
}
/**
* Implements hook_toolbar_alter().
*
* Alters the 'contextual' toolbar tab if it exists (meaning the user is allowed
* to use contextual links) and if they can administer blocks.
*
* @todo Remove the "administer blocks" requirement in https://www.drupal.org/node/2822965
* @see contextual_toolbar()
*/
function outside_in_toolbar_alter(&$items) {
$items['contextual']['#cache']['contexts'][] = 'user.permissions';
if (isset($items['contextual']['tab']) && \Drupal::currentUser()->hasPermission('administer blocks')) {
$items['contextual']['#weight'] = -1000;
$items['contextual']['#attached']['library'][] = 'outside_in/drupal.outside_in';
$items['contextual']['tab']['#attributes']['data-drupal-outsidein'] = 'toggle';
// Set a class on items to mark whether they should be active in edit mode.
// @todo Create a dynamic method for modules to set their own items.
// https://www.drupal.org/node/2784589
$edit_mode_items = ['contextual', 'block_place'];
foreach ($items as $key => $item) {
if (!in_array($key, $edit_mode_items) && (!isset($items[$key]['#wrapper_attributes']['class']) || !in_array('hidden', $items[$key]['#wrapper_attributes']['class']))) {
$items[$key]['#wrapper_attributes']['class'][] = 'edit-mode-inactive';
}
}
}
}
/**
* Implements hook_block_alter().
*/
function outside_in_block_alter(&$definitions) {
if (!empty($definitions['system_branding_block'])) {
$definitions['system_branding_block']['forms']['off_canvas'] = SystemBrandingOffCanvasForm::class;
}
// Since menu blocks use derivatives, check the definition ID instead of
// relying on the plugin ID.
foreach ($definitions as &$definition) {
if ($definition['id'] === 'system_menu_block') {
$definition['forms']['off_canvas'] = SystemMenuOffCanvasForm::class;
}
}
}
/**
* Implements hook_css_alter().
*/
function outside_in_css_alter(&$css, AttachedAssetsInterface $assets) {
// @todo Remove once conditional ordering is introduced in
// https://www.drupal.org/node/1945262.
$path = drupal_get_path('module', 'outside_in') . '/css/outside_in.theme.css';
if (isset($css[$path])) {
// Use 200 to come after CSS_AGGREGATE_THEME.
$css[$path]['group'] = 200;
}
}