Projet

Général

Profil

Paste
Télécharger (1,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / help / api-handler-area.html @ 31a5a6d6

1
In Views areas (header, footer, empty-text) are pluggable, this means you can write your own php logic to place whatever you want.
2

    
3
<h3>Requirements</h3>
4
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
5
how to extend views.
6

    
7
<h3>Create your own area handler</h3>
8

    
9
The first step is to tell views: Hey i want to add a new area handler.
10
Therefore you have to implement hook_views_data and add a new one. For example:
11

    
12
<pre>
13
function yourmodule_views_data() {
14
  $data['views']['collapsible_area'] = array(
15
    'title' =&gt; t('Collabsible Text area'),
16
    'help' =&gt; t('Provide collabsible markup text for the area.'),
17
    'area' =&gt; array(
18
      'handler' =&gt; 'yourmodule_handler_collapsible_area_text',
19
    ),
20
  );
21
  return $data;
22
}
23
</pre>
24

    
25
The second step is to write this handler. Therefore create a file called yourmodule_handler_collapsible_area_text.inc and
26
add it to the .info file of your module.
27

    
28
Then add content to your area file like this:
29
<pre>
30
class yourmodule_handler_collapsible_area_text extends views_handler_area_text {
31
  function render($empty = FALSE) {
32
    // Here you just return a string of your content you want.
33
    if ($render = parent::render($empty)) {
34
      $element = array(
35
        '#type' =&gt; 'fieldset',
36
        '#title' =&gt; t('Title'),
37
        '#value' =&gt; $render,
38
      );
39
      $output = theme('fieldset', $element);
40
      return $output;
41
    }
42
  }
43
}
44
</pre>
45

    
46
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 :)