Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / help / api-handler-area.html @ 76df55b7

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
}
22
</pre>
23

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

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

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