-
Notifications
You must be signed in to change notification settings - Fork 50
/
message.api.php
137 lines (125 loc) · 3.83 KB
/
message.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
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
<?php
/**
* @file
* Hooks provided by the Message module.
*/
use Drupal\message\Entity\Message;
/**
* @addtogroup hooks
* @{
*/
/**
* Act on a message that is being assembled before rendering.
*
* The module may add elements to $message->content prior to rendering. The
* structure of $message->content is a renderable array as expected by
* drupal_render().
*
* @param \Drupal\message\Entity\Message $message
* The message entity.
* @param string $view_mode
* The view mode the message is rendered in.
* @param string $langcode
* The language code used for rendering.
*
* @see hook_entity_prepare_view()
* @see hook_entity_view()
*/
function hook_message_view(Message $message, $view_mode, $langcode) {
$message->content['my_additional_field'] = [
'#markup' => 'foo',
'#weight' => 10,
'#theme' => 'mymodule_my_additional_field',
];
}
/**
* Alter the results of entity_view() for messages.
*
* This hook is called after the content has been assembled in a structured
* array and may be used for doing processing which requires that the complete
* message content structure has been built.
*
* If the module wishes to act on the rendered HTML of the message rather than
* the structured content array, it may use this hook to add a #post_render
* callback. Alternatively, it could also implement hook_preprocess_message().
* See drupal_render() and theme() documentation respectively for details.
*
* @param array $build
* A renderable array representing the message content.
*
* @see hook_entity_view_alter()
*/
function hook_message_view_alter(array &$build) {
if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
// Change its weight.
$build['an_additional_field']['#weight'] = -10;
// Add a #post_render callback to act on the rendered HTML of the entity.
$build['#post_render'][] = 'my_module_post_render';
}
}
/**
* Define default message template configurations.
*
* @return array
* An array of default message templates, keyed by machine names.
*
* @see hook_default_message_template_alter()
*/
function hook_default_message_template() {
$defaults['main'] = entity_create('message_template', []);
return $defaults;
}
/**
* Alter default message template configurations.
*
* @param array $defaults
* An array of default message templates, keyed by machine names.
*
* @see hook_default_message_template()
*/
function hook_default_message_template_alter(array &$defaults) {
$defaults['main']->name = 'custom name';
}
/**
* Alter message template forms.
*
* Modules may alter the message template entity form by making use of this hook
* or the entity bundle specific
* hook_form_message_template_edit_BUNDLE_form_alter(). #entity_builders may be
* used in order to copy the values of added form elements to the entity, just
* as documented for entity_form_submit_build_entity().
*
* @param array $form
* Nested array of form elements that comprise the form.
* @param array $form_state
* A keyed array containing the current state of the form.
*/
function hook_form_message_template_form_alter(array &$form, array &$form_state) {
// Your alterations.
}
/**
* Define default message template category configurations.
*
* @return array
* An array of default message template categories, keyed by machine names.
*
* @see hook_default_message_category_alter()
*/
function hook_default_message_category() {
$defaults['main'] = entity_create('message_category', []);
return $defaults;
}
/**
* Alter default message template category configurations.
*
* @param array $defaults
* An array of default message template categories, keyed by machine names.
*
* @see hook_default_message_category()
*/
function hook_default_message_category_alter(array &$defaults) {
$defaults['main']->name = 'custom name';
}
/**
* @} End of "addtogroup hooks".
*/