-
Notifications
You must be signed in to change notification settings - Fork 8
/
template.php
150 lines (132 loc) · 4.22 KB
/
template.php
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
<?php
/**
* @file
* template.php
*/
atomium_include('ec_europa', 'includes/alter');
/**
* Implements hook_date_popup_process_alter().
*/
function ec_europa_date_popup_process_alter(&$element, &$form_state, $context) {
// Removing the description from the datepicker.
unset($element['date']['#description']);
unset($element['time']['#description']);
}
/**
* Override theme_file_link().
*
* TODO: Convert this into a preprocess function.
*/
function ec_europa_file_link($variables) {
if (\function_exists('_nexteuropa_formatters_file_markup')) {
$file = $variables['file'];
// Submit the language along witht the file.
$langcode = $GLOBALS['language_content']->language;
if (!empty($langcode)) {
$file->language = $langcode;
}
return _nexteuropa_formatters_file_markup($file);
}
return theme_file_link($variables);
}
/**
* Pre-render function for taxonomy pages.
*
* TODO: This function doesn't seems to be used in this theme.
*/
function _ec_europa_term_heading($element) {
$element['#prefix'] = '<div class="ecl-container"><div class="' . $element['main'] . '">';
$element['#suffix'] = '</div></div>';
return $element;
}
/**
* Sets a form element's class attribute.
*
* Adds the css classes as needed.
*
* @param array $variables
* The $variables related to the form element theme.
* @param array $classes
* The array of class names to add to the element by default.
* @param array $error_classes
* The array of class names to add to the element in case of
* validation errors.
*
* @return array
* The modified $variables array.
*/
function _ec_europa_form_set_css_class(array &$variables, array $classes = array(), array $error_classes = array()) {
if (!empty($classes)) {
$variables['atomium']['attributes']['element']->append('class', $classes);
}
// Determines if the error class must added.
// The logic comes from the Drupal function, see _form_set_class().
if (isset($variables['element'])) {
$element = $variables['element'];
if (!empty($error_classes) && _ec_europa_has_form_element_errors($element)) {
$variables['atomium']['attributes']['element']->append('class', $error_classes);
}
}
return $variables;
}
/**
* Determines if validation errors exists on a form element.
*
* This method works only with elements processed by the theme mechanism.
*
* @param array $form_element
* The form element to test as defined in the $variable parameter of a
* preprocess function.
*
* @return bool
* True if validation errors exist; otherwise FALSE.
*/
function _ec_europa_has_form_element_errors(array $form_element) {
return isset($form_element['#parents']) && form_get_error($form_element) !== NULL && !empty($form_element['#validated']);
}
/**
* Custom implementation of tableselect.
*/
function ec_europa_tableselect($variables) {
// Add a custom JS file that overrides a specific JS function.
drupal_add_js(path_to_theme() . '/templates/table/tableselect.js', array('group' => JS_THEME));
// Use the default implementation to render the table.
// We cannot use theme('tableselect',...) or else we will end up in a loop.
// Better solutions are welcome.
return theme_tableselect($variables);
}
/**
* Case array_search() with partial matches.
*
* @param string $needle
* The string to search for.
* @param array $haystack
* The array to search in.
*
* @return mixed
* The key for needle if it is found in the
* array, FALSE otherwise.
*
* @author Bran van der Meer <[email protected]>
*/
function _ec_europa_array_find($needle, array $haystack) {
foreach ($haystack as $key => $value) {
if (\is_string($value) && \stripos($value, $needle) !== FALSE) {
return $key;
}
}
return FALSE;
}
/**
* Returns TRUE if a path is external to Drupal and 'ec.europa.eu' domain.
*
* @param string $path
* The internal path or external URL being linked to, such as "node/34" or
* "http://example.com/foo".
*
* @return bool
* Boolean TRUE or FALSE, where TRUE indicates an external path.
*/
function _ec_europa_url_is_external($path) {
return url_is_external($path) && !\stripos(\parse_url($path, PHP_URL_HOST), 'europa.eu') && \stripos(\parse_url($path, PHP_URL_HOST), $_SERVER['HTTP_HOST']) === FALSE;
}