-
Notifications
You must be signed in to change notification settings - Fork 1
/
header_footer_corporate.module
252 lines (236 loc) · 9.53 KB
/
header_footer_corporate.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?php
/**
* @file
* Drupal needs this blank file.
*/
use HeaderFooterCorporate\HeaderFooterCorporateHelpers;
include_once 'header_footer_corporate.helpers.inc';
// Import differents '.component.inc' files (as Atomium theme) from templates/.
$directory = new RecursiveDirectoryIterator(__DIR__ . '/templates/');
$iterator = new RecursiveIteratorIterator($directory);
$regex = new RegexIterator($iterator, '/^.+\.component.inc$/i', RecursiveRegexIterator::GET_MATCH);
foreach ($regex as $name => $regex) {
include $name;
}
/**
* Implements hook_theme().
*/
function header_footer_corporate_theme() {
return array(
'header_ec_corporate' => array(
'template' => 'templates/header-ec-corporate',
),
'footer_ec_corporate' => array(
'template' => 'templates/footer-ec-corporate',
),
'breadcrumb_ec_corporate' => array(
'template' => 'templates/breadcrumb-ec-corporate',
),
'menu_items_ec_corporate_lists' => array(
'file' => 'themes/menu_items_ec_corporate_lists.theme.inc',
'arguments' => array(
'variables' => array(
'links' => array(
'href',
'language',
),
'attributes' => array(
'id',
'class',
),
'heading' => array(
'class',
),
),
),
),
'menu_items_ec_corporate_links' => array(
'template' => 'menu-items-ec-corporate-links',
'arguments' => array(
'variables' => array(
'links' => array(
'href',
'language',
),
'attributes' => array(
'id',
'class',
),
'heading' => array(
'class',
'level',
'text',
),
),
),
),
);
}
/**
* Implements hook_theme_registry_alter().
*/
function header_footer_corporate_theme_registry_alter(&$theme_registry) {
// ################
// Add templates in custom modules :
// Source : https://www.drupal.org/docs/7/creating-custom-modules/howtos/using-template-tplphp-files-in-your-own-module.
// Defined path to the current module.
$module_path = drupal_get_path('module', 'header_footer_corporate');
// Find all .tpl.php files in this module's folder recursively.
$template_file_objects = drupal_find_theme_templates($theme_registry, '.tpl.php', $module_path);
// Iterate through all found template file objects.
foreach ($template_file_objects as $key => $template_file_object) {
// If the template has not already been overridden by a theme.
if (!isset($theme_registry[$key]['theme path']) || !preg_match('#/themes/#', $theme_registry[$key]['theme path'])) {
// Alter the theme path and template elements.
$theme_registry[$key]['theme path'] = $module_path;
$theme_registry[$key] = array_merge($theme_registry[$key], $template_file_object);
$theme_registry[$key]['type'] = 'module';
}
}
// ################
// Redefine the theme_button() function.
$theme_registry['button']['function'] = '_header_footer_corporate_theme_button';
$theme_registry['button']['includes'] = array($module_path . '/themes/button.theme.inc');
// Redefine the theme_easy_breadcrumb() from easy_breadcrumb.module.
$theme_registry['easy_breadcrumb']['function'] = '_header_footer_corporate_theme_breadcrumb';
$theme_registry['easy_breadcrumb']['includes'] = array($module_path . '/themes/easy_breadcrumb.theme.inc');
}
/**
* Implenents hook_form_FORM_ID_alter().
*/
function header_footer_corporate_form__easy_breadcrumb_general_settings_form_alter(&$form, &$form_state, $form_id) {
$form['easy_breadcrumb']['#description'] = t('<i>Some settings had been removed by <b>Header Footer Corporate</b> module because it is not used in the Corporate breadcrumb.</i>');
$form['easy_breadcrumb']['easy_breadcrumb-disable_drupal_breadcrumb']['#access'] = FALSE;
$form['easy_breadcrumb']['easy_breadcrumb-include_title_segment']['#access'] = FALSE;
$form['easy_breadcrumb']['easy_breadcrumb-title_from_page_when_available']['#access'] = FALSE;
$form['easy_breadcrumb']['easy_breadcrumb-title_segment_as_link']['#access'] = FALSE;
$form['easy_breadcrumb']['easy_breadcrumb-capitalizator_mode']['#access'] = FALSE;
$form['easy_breadcrumb']['easy_breadcrumb-segments_separator']['#access'] = FALSE;
$form['easy_breadcrumb']['easy_breadcrumb-capitalizator_ignored_words']['#access'] = FALSE;
$form['easy_breadcrumb']['easy_breadcrumb-home_segment_title']['#states'] = array(
'invisible' => array(
':input[name="easy_breadcrumb-include_home_segment"]' => array('checked' => FALSE),
));
}
/**
* Implenents hook_form_FORM_ID_alter().
*/
function header_footer_corporate_form_nexteuropa_europa_search_search_form_alter(&$form, &$form_state, $form_id) {
global $language;
// Form element.
$form['#attributes']['class'] = array(
'ecl-site-header__search',
'ecl-search-form',
);
$form['#attributes']['role'] = array('search');
// Wrapper.
$form['search_input_group']['#prefix'] = '';
$form['search_input_group']['#suffix'] = '';
// Textfield.
// Flag to contextualize in HOOK_process_textfield.
$form['search_input_group']['QueryText']['#ecl-header_footer_corporate']['header'] = TRUE;
// Button (also managed in button.theme.inc).
$form['search_input_group']['europa_search_submit']['#ecl-buttontype'] = 'button';
$form['search_input_group']['europa_search_submit']['#attributes']['class'] = array(
'ecl-button',
'ecl-search-form__button',
'ecl-button--search',
);
$form['search_input_group']['europa_search_submit']['#value'] =
'<span class="ecl-button__container">' .
'<span class="ecl-button__label" data-ecl-label="true">' . i18n_string_translate('blocks:nexteuropa_europa_search:nexteuropa_europa_search_form:title', 'Search', array('langcode' => $language->language)) . '</span>' .
'<svg focusable="false" aria-hidden="true" data-ecl-icon="true" class="ecl-button__icon ecl-button__icon--after ecl-icon ecl-icon--xs"><use xlink:href="' . HeaderFooterCorporateHelpers::getAssetsPath() . '/images/icons/sprites/icons.svg#general--search"></use></svg>' .
'</span></button>';
}
/**
* Implenents hook_form_FORM_ID_alter().
*/
function header_footer_corporate_form_menu_edit_item_alter(&$form, &$form_state, $form_id) {
// Set predefined values for the menu "Footer - Follow us".
if ($form['parent']['#default_value'] == 'menu-footer-follow-us:0') {
$options = array();
foreach (HeaderFooterCorporateHelpers::getSocialMediaNetworksValues() as $name) {
$options[$name] = $name;
}
$form['original_item']['#value']['options']['attributes']['class'] = array();
$form['link_title'] = array_merge($form['link_title'], array(
'#type' => 'select',
'#options' => $options,
));
}
}
/**
* Implements hook_context_load_alter().
*/
function header_footer_corporate_context_load_alter(&$context) {
// Remove breadcrumb and footer setted by platform.
if ($context->name === 'site_wide') {
if (isset($context->reactions['block']['blocks']['easy_breadcrumb-easy_breadcrumb'])) {
unset($context->reactions['block']['blocks']['easy_breadcrumb-easy_breadcrumb']);
}
if (isset($context->reactions['block']['blocks']['footer']) &&
$context->reactions['block']['blocks']['footer']['delta'] == 'footer_ipg') {
unset($context->reactions['block']['blocks']['footer']);
}
}
}
/**
* Implements hook_preprocess().
*/
function header_footer_corporate_preprocess(&$variables, $hook) {
switch ($hook) {
case 'page':
case 'maintenance_page':
$variables['header_ec_corporate'] =
$variables['footer_ec_corporate'] = '';
if (!path_is_admin(current_path())) {
// JS.
drupal_add_js('https://unpkg.com/[email protected]/dist/svg4everybody.js', array(
'type' => 'external',
'scope' => 'footer',
'group' => JS_THEME,
));
drupal_add_js(HeaderFooterCorporateHelpers::getAssetsPath('path') . '/scripts/ecl-ec-preset-legacy-website.js', array(
'type' => 'external',
'scope' => 'footer',
'group' => JS_THEME,
));
drupal_add_js('svg4everybody({ polyfill: true });ECL.autoInit();', array(
'type' => 'inline',
'scope' => 'footer',
'group' => JS_THEME,
));
// CSS.
drupal_add_css(HeaderFooterCorporateHelpers::getAssetsPath('path') . '/styles/ecl-ec-preset-legacy-website.css',
array(
'type' => 'external',
// More than CSS_THEME (=100) to not be overrided.
'group' => 300,
'weight' => 100,
));
drupal_add_css(HeaderFooterCorporateHelpers::getAssetsPath('path') . '/styles/ecl-ec-preset-legacy-website-print.css',
array(
'type' => 'external',
// More than CSS_THEME (=100) to not be overrided.
'group' => 300,
'weight' => 100,
'media' => 'print',
));
drupal_add_css(drupal_get_path('module', 'header_footer_corporate') . '/css/header_footer_corporate.css',
array(
// More than CSS_THEME (=100) to not be overrided.
'group' => 300,
'weight' => 101,
'cache' => FALSE,
));
// Define custom variables to be used in .tpl files.
$variables['header_ec_corporate'] = theme('header_ec_corporate', array(
'site_name' => $variables['site_name'],
));
$variables['footer_ec_corporate'] = theme('footer_ec_corporate', array(
'site_name' => $variables['site_name'],
));
}
break;
}
}