-
Notifications
You must be signed in to change notification settings - Fork 0
/
varbase_media_header.module
executable file
·166 lines (138 loc) · 5.58 KB
/
varbase_media_header.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
* @file
* Contains varbase_media_header.module.
*/
use Drupal\node\NodeInterface;
use Drupal\taxonomy\TermInterface;
use Drupal\Core\Form\FormStateInterface;
// Include all helpers.
include_once __DIR__ . '/includes/helpers.inc';
/**
* Implements hook_form_FORM_ID_alter().
*/
function varbase_media_header_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$vmh_settings = \Drupal::config('varbase_media_header.settings')->get('varbase_media_header_settings');
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('node');
foreach ($bundles as $bundle_key => $bundle) {
if (!empty($vmh_settings['node']) && isset($vmh_settings['node'][$bundle_key]) && $vmh_settings['node'][$bundle_key]) {
if ($form_id == 'node_' . $bundle_key . '_edit_form'
|| $form_id == 'node_' . $bundle_key . '_form') {
varbase_media_header__node_group_form($form, $form_state, $form_id);
}
}
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function varbase_media_header_form_taxonomy_term_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$vmh_settings = \Drupal::config('varbase_media_header.settings')->get('varbase_media_header_settings');
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('taxonomy_term');
foreach ($bundles as $bundle_key => $bundle) {
if (!empty($vmh_settings['taxonomy_term']) && isset($vmh_settings['taxonomy_term'][$bundle_key]) && $vmh_settings['taxonomy_term'][$bundle_key]) {
if ($form_id == 'taxonomy_term_' . $bundle_key . '_edit_form'
|| $form_id == 'taxonomy_term_' . $bundle_key . '_form') {
varbase_media_header__taxonomy_term_group_form($form, $form_state, $form_id);
}
}
}
}
/**
* Implements hook_preprocess_block().
*/
function varbase_media_header_preprocess_block(&$variables) {
$active_theme = \Drupal::config('system.theme')->get('default');
$current_theme = \Drupal::theme()->getActiveTheme()->getName();
if (($variables['plugin_id'] == 'page_title_block'
|| $variables['plugin_id'] == 'system_breadcrumb_block')
&& $active_theme == $current_theme) {
$entity = FALSE;
$entity_type = FALSE;
$node = new stdClass();
$route_name = \Drupal::routeMatch()->getRouteName();
if ($route_name == 'entity.node.canonical') {
$node = \Drupal::routeMatch()->getParameter('node');
}
elseif ($route_name == 'entity.node.latest_version') {
$latest_version_node = \Drupal::routeMatch()->getParameter('node');
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
$storage = \Drupal::entityTypeManager()->getStorage('node');
$last_revision_id = $storage->getLatestRevisionId($latest_version_node->id());
$node = $storage->loadRevision($last_revision_id);
}
elseif ($route_name == 'entity.node.preview'
&& \Drupal::routeMatch()->getParameter('view_mode_id') == 'full') {
$node = \Drupal::routeMatch()->getParameter('node_preview');
}
if ($node instanceof NodeInterface && isset($node)) {
$entity = $node;
$entity_type = $entity->getEntityType()->id();
}
else {
$taxonomy = \Drupal::routeMatch()->getParameter('taxonomy_term');
if ($taxonomy instanceof TermInterface && isset($taxonomy)) {
$entity = $taxonomy;
$entity_type = $entity->getEntityType()->id();
}
}
if ($entity_type != FALSE) {
$vmh_settings = \Drupal::config('varbase_media_header.settings')->get('varbase_media_header_settings');
if (!empty($vmh_settings[$entity_type])
&& isset($vmh_settings[$entity_type][$entity->bundle()])
&& $vmh_settings[$entity_type][$entity->bundle()]
&& $entity->hasField('field_page_header_style')
&& !$entity->get('field_page_header_style')->isEmpty()
&& $entity->get('field_page_header_style')->value != 'standard') {
$vmh_hide_breadcrumbs = \Drupal::config('varbase_media_header.settings')->get('hide_breadcrumbs');
if ($variables['plugin_id'] == 'system_breadcrumb_block'
&& isset($vmh_hide_breadcrumbs)
&& $vmh_hide_breadcrumbs == FALSE) {
$variables['content'] = '';
}
elseif ($variables['plugin_id'] == 'page_title_block') {
$variables['content'] = '';
}
}
$variables['#cache']['contexts'][] = 'url';
}
}
}
/**
* Implements hook_theme().
*/
function varbase_media_header_theme($existing, $type, $theme, $path) {
return [
'varbase_media_header_block' => [
'variables' => [
'title' => 'Varbase Media Header',
'description' => NULL,
'vmh_page_title' => NULL,
'vmh_page_breadcrumbs' => NULL,
'vmh_background_media' => NULL,
'vmh_media_type' => NULL,
'provider' => NULL,
],
],
'media_oembed_iframe__remote_video__varbase_media_header' => [
'template' => 'media-oembed-iframe--remote-video--varbase-media-header',
'variables' => [
'provider' => NULL,
'media' => NULL,
],
],
];
}
/**
* Implements hook_preprocess_HOOK().
*/
function varbase_media_header_preprocess_media_oembed_iframe__remote_video__varbase_media_header(&$variables) {
// Suggestions go here!
$module_handler = \Drupal::service('module_handler');
$query = \Drupal::request()->query;
$variables['type'] = $query->get('type');
$variables['provider'] = $query->get('provider');
$variables['view_mode'] = $query->get('view_mode');
$variables['base_path'] = base_path();
$variables['varbase_media_header_path'] = $module_handler->getModule('varbase_media_header')->getPath();
}