-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathopenemr.theme
89 lines (77 loc) · 2.77 KB
/
openemr.theme
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
<?php
/**
* @file
* Functions to support theming in the theme.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\media\Entity\Media;
use Drupal\file\Entity\File;
use Drupal\node\Entity\Node;
function openemr_form_system_theme_settings_alter(&$form, FormStateInterface &$form_state, $form_id = NULL) {
// Work-around for a core bug affecting admin themes. See issue #943212.
if (isset($form_id)) {
return;
}
$form['openemr_cover_image_field'] = array(
'#type' => 'textfield',
'#title' => t('Blog Cover Image Field Name'),
'#default_value' => theme_get_setting('openemr_cover_image_field'),
'#description' => t("Machine name for blog posts."),
);
}
function openemr_theme_suggestions_block_alter(array &$suggestions, array $vars) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$last = end($suggestions);
reset($suggestions);
$suggestion = $last . '_' . $node->bundle();
$suggestions[] = $suggestion;
}
}
function openemr_preprocess_block(array &$vars) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
if ($node->getType() == 'blog_post') {
$vars['background'] = openemr_create_uri_for_background_image($node);
}
}
}
function openemr_preprocess_node(&$variables) {
$variables['openemr_cover_image_field'] = theme_get_setting('openemr_cover_image_field');
}
function openemr_preprocess_page(&$vars) {
$fullWidthContentTypes = [
'blog_post',
];
$vars['container'] = 'container';
if ($node = \Drupal::routeMatch()->getParameter('node')) {
if (in_array($node->getType(), $fullWidthContentTypes)) {
$vars['container'] = 'container-fluid';
}
}
}
function openemr_theme_suggestions_page_alter(&$suggestions, $vars, $hook) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$content_type = $node->bundle();
$suggestions[] = 'page__' . $content_type;
}
}
function openemr_create_uri_for_background_image(Node $node) {
$image_field = theme_get_setting('openemr_cover_image_field');
if ($image = $node->get($image_field)->first()->getValue()) {
$media = Media::load($image['target_id']);
$media_field = $media->get('image')->first()->getValue();
$file = File::load($media_field['target_id']);
if ($file) {
$background = $file->getFileUri();
return file_create_url($background);
}
}
}
function openemr_preprocess_paragraph__banner(&$variables) {
$paragraph = $variables['paragraph'];
if (!$paragraph->field_image->isEmpty()) {
$image = $paragraph->field_image->entity->url();
$variables['attributes']['style'][] = 'background-image: url("' . $image . '");';
$variables['attributes']['style'][] = 'background-size: cover;';
$variables['attributes']['style'][] = 'background-position: center center;';
}
}