-
Notifications
You must be signed in to change notification settings - Fork 0
/
views_attachment_blocks_plugin_attachment_block.inc
137 lines (117 loc) · 4.07 KB
/
views_attachment_blocks_plugin_attachment_block.inc
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
<?php
// $Id: views_attachment_blocks_plugin_attachment_header_node.inc,v 1.1.2.4 2010/09/21 16:52:19 joachim Exp $
/**
* The plugin that handles a header node attachment display.
*
* A header node attachment display outputs the content of the node found at the
* path 'VIEWPATH/text'. This allows non-admins to easily edit the effective
* header or footer text of the view.
*
* @todo:
* - add a setting for either the complete path, or the path suffix,
* or even a node autocomplete selection widget.
* - if basing the path on the view's path, send arguments.
* - consider using title rather than path??
* - pass arguments by validated value: reach into $this->view->argument and
* pass values from that.
* - work with prepopulate module to give admins a 'create header for this view'
* that fills in the URL path setting automatically.
*/
class views_attachment_blocks_plugin_attachment_block extends views_plugin_display_attachment {
/**
* Provide the summary for attachment options in the views UI.
*
* This output is returned as an array.
*/
function options_summary(&$categories, &$options) {
// It is very important to call the parent function here:
parent::options_summary($categories, $options);
$options['block'] = array(
'category' => 'attachment',
'title' => t('Block'),
'value' => $this->get_option('block') ? $this->get_option('block') : 'None',
);
}
function option_definition () {
$options = parent::option_definition();
$options['block'] = array('default' => 0);
return $options;
}
/**
* Provide the default form for setting options.
*/
function options_form(&$form, &$form_state) {
// It is very important to call the parent function here:
parent::options_form($form, $form_state);
$default_theme = variable_get('theme_default', 'garland');
$blocks = array();
$blocks[0] = t('Select a block...');
foreach ( _block_rehash($default_theme) as $idx => $block ) {
$block_key = $block['module'] . '_' . $block['delta'];
$blocks[$block_key] = $block['info'];
}
switch ($form_state['section']) {
case 'block':
$form['#title'] .= t('Block');
$form['block'] = array(
'#type' => 'select',
'#description' => t('The block to render as the content for this attachment.'),
'#options' => $blocks,
'#default_value' => $this->get_option('block'),
);
break;
}
}
/**
* Perform any necessary changes to the form values prior to storage.
* There is no need for this function to actually store the data.
*/
function options_submit(&$form, &$form_state) {
// It is very important to call the parent function here:
parent::options_submit($form, $form_state);
switch ($form_state['section']) {
case 'block':
$this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
break;
}
}
/**
* Attach to another view.
*/
function attach_to($display_id) {
$displays = $this->get_option('displays');
if (empty($displays[$display_id])) {
return;
}
if (!$this->access()) {
return;
}
$attachment = $this->get_block_content();
switch ($this->get_option('attachment_position')) {
case 'before':
$this->view->attachment_before .= $attachment;
break;
case 'after':
$this->view->attachment_after .= $attachment;
break;
case 'both':
$this->view->attachment_before .= $attachment;
$this->view->attachment_after .= $attachment;
break;
}
}
/**
* Get the content to show as this view's header.
*/
function get_block_content() {
$block_key = $this->get_option('block');
if ( $block_key ) {
$block_id = explode('_', $block_key);
$block = (object)module_invoke($block_id[0], 'block', 'view', $block_id[1]);
$block->module = $block_id[0];
$block->delta = $block_id[1];
return theme('block', $block);
}
return;
}
}