-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonified.module
72 lines (65 loc) · 1.76 KB
/
personified.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
<?php
/**
* @file
* Personified module.
*/
use Drupal\Component\Utility\Html;
/**
* Implements hook_theme().
*/
function personified_theme() {
return [
'personified_data' => [
'variables' => [
'endpoint' => '',
'template' => '',
'params' => [],
],
],
'personified_message' => [
'variables' => [
'template' => '',
'transformer' => '',
],
],
];
}
/**
* Prepares variables for a Personified Data template.
*
* Default template: personified-data.html.twig.
*
* @param array $variables
* An associative array containing:
* - content: An array of block types.
*/
function template_preprocess_personified_data(&$variables) {
$counter = &drupal_static(__FUNCTION__, 0);
$id = Html::getId('personified-data-' . $counter++);
$variables['attributes']['id'] = $id;
$variables['#attached']['library'][] = 'personified/data';
$variables['#attached']['drupalSettings']['personifiedData'][$id] = [
'endpoint' => $variables['endpoint'],
'template' => $variables['template'],
'params' => $variables['params'],
];
}
/**
* Prepares variables for a Personified Message template.
*
* Default template: personified-message.html.twig.
*
* @param array $variables
* An associative array containing:
* - content: An array of block types.
*/
function template_preprocess_personified_message(&$variables) {
$counter = &drupal_static(__FUNCTION__, 0);
$id = Html::getId('personified-message-' . $counter++);
$variables['attributes']['id'] = $id;
$variables['#attached']['library'][] = 'personified/message';
$variables['#attached']['drupalSettings']['personifiedMessage'][$id] = [
'template' => $variables['template'],
'transformer' => $variables['transformer'],
];
}