-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock_list_override.module
50 lines (43 loc) · 1.58 KB
/
block_list_override.module
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
<?php
/**
* @file
* Contains block_list_override.module.
*/
/**
* Implements hook_block_alter().
*/
function block_list_override_block_alter(&$definitions) {
$listService = \Drupal::service('block_list_override.list');
$settings = \Drupal::config('block_list_override.settings');
$options = [
'match' => trim($settings->get('system_match') ?? ''),
'prefix' => trim($settings->get('system_prefix') ?? ''),
'regex' => trim($settings->get('system_regex') ?? ''),
'negate' => !empty($settings) ? $settings->get('system_negate') : FALSE,
];
$listService->setUp($options);
if (!$listService->hasSettings()) {
return;
}
$callback = [$listService, 'blockIsAllowed'];
$definitions = array_filter($definitions, $callback, ARRAY_FILTER_USE_KEY);
}
/**
* Implements hook_plugin_filter_TYPE__CONSUMER_alter().
*/
function block_list_override_plugin_filter_block__layout_builder_alter(&$definitions) {
$listService = \Drupal::service('block_list_override.list');
$settings = \Drupal::config('block_list_override.settings');
$options = [
'match' => !empty($settings) ? trim($settings->get('layout_match')) : '',
'prefix' => !empty($settings) ? trim($settings->get('layout_prefix')) : '',
'regex' => !empty($settings) ? trim($settings->get('layout_regex')) : '',
'negate' => !empty($settings) ? $settings->get('layout_negate') : FALSE,
];
$listService->setUp($options);
if (!$listService->hasSettings()) {
return;
}
$callback = [$listService, 'blockIsAllowed'];
$definitions = array_filter($definitions, $callback, ARRAY_FILTER_USE_KEY);
}