-
Notifications
You must be signed in to change notification settings - Fork 56
/
ui_patterns.module
76 lines (65 loc) · 2.27 KB
/
ui_patterns.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
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
<?php
/**
* @file
* Contains ui_patterns.module.
*/
use Drupal\ui_patterns\UiPatterns;
use Drupal\ui_patterns\Element\PatternContext;
/**
* Implements hook_theme().
*/
function ui_patterns_theme() {
/** @var \Drupal\ui_patterns\Plugin\PatternBase $pattern */
$items = [
'patterns_destination' => [
'variables' => ['sources' => NULL, 'context' => NULL],
],
'patterns_use_wrapper' => [
'variables' => ['use' => NULL],
],
];
foreach (UiPatterns::getManager()->getPatterns() as $pattern) {
$items += $pattern->getThemeImplementation();
}
return $items;
}
/**
* Implements hook_library_info_build().
*/
function ui_patterns_library_info_build() {
/** @var \Drupal\ui_patterns\Plugin\PatternBase $pattern */
$definitions = [];
foreach (UiPatterns::getManager()->getPatterns() as $pattern) {
$definitions += $pattern->getLibraryDefinitions();
}
return $definitions;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function ui_patterns_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
if (UiPatterns::getManager()->isPatternHook($hook)) {
\Drupal::moduleHandler()->alter('ui_patterns_suggestions', $suggestions, $variables, $variables['context']);
\Drupal::theme()->alter('ui_patterns_suggestions', $suggestions, $variables, $variables['context']);
}
if ($hook == 'patterns_destination') {
\Drupal::moduleHandler()->alter('ui_patterns_destination_suggestions', $suggestions, $variables, $variables['context']);
\Drupal::theme()->alter('ui_patterns_destination_suggestions', $suggestions, $variables, $variables['context']);
}
}
/**
* Implements hook_ui_patterns_suggestions_alter().
*/
function ui_patterns_ui_patterns_suggestions_alter(array &$suggestions, array $variables, PatternContext $context) {
// Add preview theme suggestion.
if ($context->isOfType('preview')) {
$suggestions[] = $variables['theme_hook_original'] . '__preview';
}
if (!empty($variables['variant'])) {
$suggestions[] = $variables['theme_hook_original'] . '__variant_' . $variables['variant'];
// Add variant preview theme suggestion.
if ($context->isOfType('preview')) {
$suggestions[] = $variables['theme_hook_original'] . '__variant_' . $variables['variant'] . '__preview';
}
}
}