api-handler-area.html
1.59 KB
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
In Views areas (header, footer, empty-text) are pluggable, this means you can write your own php logic to place whatever you want.
<h3>Requirements</h3>
You should have read <a href="topic:views/api">API</a> and <a href="topic:views/api-tables">Tables API</a> to get a basic knowledge
how to extend views.
<h3>Create your own area handler</h3>
The first step is to tell views: Hey i want to add a new area handler.
Therefore you have to implement hook_views_data and add a new one. For example:
<pre>
function yourmodule_views_data() {
$data['views']['collapsible_area'] = array(
'title' => t('Collabsible Text area'),
'help' => t('Provide collabsible markup text for the area.'),
'area' => array(
'handler' => 'yourmodule_handler_collapsible_area_text',
),
);
}
</pre>
The second step is to write this handler. Therefore create a file called yourmodule_handler_collapsible_area_text.inc and
add it to the .info file of your module.
Then add content to your area file like this:
<pre>
class yourmodule_handler_collapsible_area_text extends views_handler_area_text {
function render($empty = FALSE) {
// Here you just return a string of your content you want.
if ($render = parent::render($empty)) {
$element = array(
'#type' => 'fieldset',
'#title' => t('Title'),
'#value' => $render,
);
$output = theme('fieldset', $element);
return $output;
}
}
}
</pre>
As on every handler you can add options so you can configure the behavior. If the area isn't shown yet in the views interface, please clear the cache :)