-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwidget.module
89 lines (84 loc) · 3.07 KB
/
widget.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
<?php
/**
* @file
* Module file for the widget module.
*/
use Drupal\Component\Utility\Html;
/**
* Implements hook_theme().
*/
function widget_theme() {
return array(
'widget_main_with_quicktabs' => array(
'variables' => array('regions' => array()),
'template' => 'widget-main-with-quicktabs',
),
'widget_1col' => array(
'variables' => array('regions' => array(), 'label' => NULL),
'template' => 'widget-1col',
),
'widget_2col' => array(
'variables' => array('regions' => array(), 'label' => NULL),
'template' => 'widget-2col',
),
'widget_2col_2' => array(
'variables' => array('regions' => array(), 'label' => NULL),
'template' => 'widget-2col-2',
),
'widget_2col_2_1' => array(
'variables' => array('regions' => array(), 'label' => NULL),
'template' => 'widget-2col-2-1',
),
'widget_3col' => array(
'variables' => array('regions' => array(), 'label' => NULL),
'template' => 'widget-3col',
),
);
}
/**
* Prepares tabs data for the quicktab layout template.
*/
function widget_preprocess_widget_main_with_quicktabs(&$variables) {
$variables['tabs'] = array();
foreach ($variables['regions'] as $tab_id => $content) {
// @todo this condition is not nice, instead it should be possible to have
// multiple blocks in one region.
// Only add blocks that are in a "tab" region.
if (strpos($tab_id, 'tab_')) {
if (!empty($variables['regions'][$tab_id]['#blocks'])) {
// Don't print the label as it's used as tab title label.
$variables['regions'][$tab_id]['#blocks'][0]['#configuration']['label_display'] = FALSE;
// Add data: label and content of each tab.
$variables['tabs'][$tab_id] = array(
'label' => $variables['regions'][$tab_id]['#blocks'][0]['#configuration']['label'],
'content' => $variables['regions'][$tab_id]['#blocks'],
// @todo would maybe make sense to make this configurable.
'id' => 'widget-tab-' . Html::cleanCssIdentifier($tab_id),
);
}
}
}
ksort($variables['tabs']);
}
/**
* Alters label display for widget blocks with certain layouts.
*
* Moves the label into the links region or unsets that region if label display
* is disabled.
*/
function widget_preprocess_block(&$variables) {
if ($variables['plugin_id'] == 'widget_block' && in_array($variables['configuration']['layout'], array('widget_1col', 'widget_2col', 'widget_2col_2', 'widget_2col_2_1', 'widget_3col'))) {
if ($variables['configuration']['label_display']) {
$variables['content']['#label'] = isset($variables['elements']['content']['#regions']['main']['#blocks'][0]['content']['#widget_title']) ?
$variables['elements']['content']['#regions']['main']['#blocks'][0]['content']['#widget_title'] :
$variables['label'];
$variables['label'] = NULL;
}
else {
unset($variables['content']['#regions']['links']);
}
if(isset($variables['configuration']['classes'])) {
$variables['classes'] = $variables['configuration']['classes'];
}
}
}