-
Notifications
You must be signed in to change notification settings - Fork 56
/
ui_patterns.api.php
85 lines (76 loc) · 2.71 KB
/
ui_patterns.api.php
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
<?php
/**
* @file
* API file.
*/
use Drupal\ui_patterns\Element\PatternContext;
/**
* Alter UI Patterns definitions.
*
* @param \Drupal\ui_patterns\Definition\PatternDefinition[] $definitions
* Pattern definitions.
*
* @see \Drupal\ui_patterns\UiPatternsManager
*/
function hook_ui_patterns_info_alter(array &$definitions) {
$definitions['my_pattern']->setLabel('My new label');
}
/**
* Alter UI Patterns Source definitions.
*
* @see \Drupal\ui_patterns\UiPatternsSourceManager
*/
function hook_ui_patterns_ui_patterns_source_info_alter(&$definitions) {
$definitions['my_field_source']['tags'][] = 'new_tag';
}
/**
* Provide hook theme suggestions for patterns.
*
* @see ui_patterns_theme_suggestions_alter()
*/
function hook_ui_patterns_suggestions_alter(array &$suggestions, array $variables, PatternContext $context) {
if ($context->isOfType('views_row')) {
$hook = $variables['theme_hook_original'];
$view_name = $context->getProperty('view_name');
$display = $context->getProperty('display');
$suggestions[] = $hook . '__views_row__' . $view_name;
$suggestions[] = $hook . '__views_row__' . $view_name . '__' . $display;
}
}
/**
* Provide hook theme suggestions for patterns destination wrapper.
*
* A pattern render element having '#multiple_sources' set to TRUE can render
* multiple sources on the same destination field. Sources will be rendered
* using the 'patterns_destination' theme function which will use the
* 'patterns-destination.html.twig' template file.
*
* Developers can take over rendering of the template above by providing proper
* suggestions, this is useful in case you wish to provide separators or other
* wrapping elements.
*
* @see ui_patterns_theme_suggestions_alter()
* @see \Drupal\ui_patterns\Element\Pattern::processMultipleSources()
*/
function hook_ui_patterns_destination_suggestions_alter(array &$suggestions, array $variables, PatternContext $context) {
if ($context->isOfType('views_row')) {
$hook = $variables['theme_hook_original'];
$view_name = $context->getProperty('view_name');
$display = $context->getProperty('display');
$pattern = $context->getProperty('pattern');
$field = $context->getProperty('field');
$suggestions[] = $hook . '__views_row__' . $view_name . '__' . $pattern . '__' . $field;
$suggestions[] = $hook . '__views_row__' . $view_name . '__' . $display . '__' . $pattern . '__' . $field;
}
}
/**
* Alter pattern settings form under "Manage display".
*
* @param array $form
* Pattern settings fieldset.
* @param array $configuration
* Pattern configuration.
*/
function hook_ui_patterns_display_settings_form_alter(array &$form, array $configuration) {
$form['element'] = ['#type' => 'input'];
}