forked from OS2web/os2web_contact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os2web_contact.module
53 lines (47 loc) · 1.44 KB
/
os2web_contact.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
<?php
/**
* @file
* OS2Web Contact module file.
*/
use Drupal\Core\Render\Element;
/**
* Implements hook_theme().
*/
function os2web_contact_theme() {
return [
'os2web_contact' => [
'render element' => 'elements',
],
];
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function os2web_contact_theme_suggestions_os2web_contact(array $variables) {
$suggestions = [];
$contact = $variables['elements']['#os2web_contact'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
$suggestions[] = 'os2web_contact__' . $sanitized_view_mode;
$suggestions[] = 'os2web_contact__' . $contact->id();
$suggestions[] = 'os2web_contact__' . $contact->id() . '__' . $sanitized_view_mode;
return $suggestions;
}
/**
* Prepares variables for OS2Web Contact templates.
*
* Default template: os2web_contact.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_os2web_contact(array &$variables) {
// Fetch Contact Entity Object.
$os2web_contact = $variables['elements']['#os2web_contact'];
$variables['contact'] = $os2web_contact;
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}