-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmt_layout_builder.module
More file actions
59 lines (51 loc) · 1.91 KB
/
Copy pathmt_layout_builder.module
File metadata and controls
59 lines (51 loc) · 1.91 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
<?php
/**
* @file
* Primary module hooks for Mt Layout Builder module.
*
*/
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Html;
/**
* Implements hook_page_attachments().
*/
function mt_layout_builder_page_attachments(array &$attachments) {
$attachments['#attached']['library'][] = 'mt_layout_builder/mt-layout-builder';
}
/**
* Implements hook_contextual_links_alter().
*/
function mt_layout_builder_contextual_links_alter(array &$links, $group, array $route_parameters) {
if (isset($links['layout_builder_block_update'])) {
$current_data = json_decode($links['layout_builder_block_update']['localized_options']['attributes']['data-dialog-options'],true);
$current_data['dialogClass'] = "region--bright-background";
$updated_data = json_encode($current_data);
$links['layout_builder_block_update']['localized_options']['attributes']['data-dialog-options'] = $updated_data;
}
}
/**
* Implements hook_link_alter().
*/
function mt_layout_builder_link_alter(&$variables) {
/** @var Drupal\Core\Url $url */
$url = $variables['url'];
if (!$url->isRouted()) {
return;
}
$route_name = $url->getRouteName();
if ($route_name !== 'layout_builder.add_block' && $route_name !== 'layout_builder.update_block') {
return;
}
if (!in_array('use-ajax', $variables['options']['attributes']['class'], TRUE)) {
return;
}
$current_data = json_decode($variables['options']['attributes']['data-dialog-options'],true);
$current_data['dialogClass'] = "region--bright-background";
$updated_data = json_encode($current_data);
$variables['options']['attributes']['data-dialog-options'] = $updated_data;
if (isset($url->getRouteParameters()['plugin_id'])) {
$block_plugin_id = $url->getRouteParameters()['plugin_id'];
$machine_name = Html::cleanCssIdentifier(explode(":", $block_plugin_id));
$variables['options']['attributes']['class'][] = end($machine_name);
}
}