Mercurial > hg > rr-repo
annotate sites/all/modules/views/help/api-handler-area.html @ 0:ff03f76ab3fe
initial version
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Wed, 21 Aug 2013 18:51:11 +0100 |
parents | |
children |
rev | line source |
---|---|
danielebarchiesi@0 | 1 In Views areas (header, footer, empty-text) are pluggable, this means you can write your own php logic to place whatever you want. |
danielebarchiesi@0 | 2 |
danielebarchiesi@0 | 3 <h3>Requirements</h3> |
danielebarchiesi@0 | 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 |
danielebarchiesi@0 | 5 how to extend views. |
danielebarchiesi@0 | 6 |
danielebarchiesi@0 | 7 <h3>Create your own area handler</h3> |
danielebarchiesi@0 | 8 |
danielebarchiesi@0 | 9 The first step is to tell views: Hey i want to add a new area handler. |
danielebarchiesi@0 | 10 Therefore you have to implement hook_views_data and add a new one. For example: |
danielebarchiesi@0 | 11 |
danielebarchiesi@0 | 12 <pre> |
danielebarchiesi@0 | 13 function yourmodule_views_data() { |
danielebarchiesi@0 | 14 $data['views']['collapsible_area'] = array( |
danielebarchiesi@0 | 15 'title' => t('Collabsible Text area'), |
danielebarchiesi@0 | 16 'help' => t('Provide collabsible markup text for the area.'), |
danielebarchiesi@0 | 17 'area' => array( |
danielebarchiesi@0 | 18 'handler' => 'yourmodule_handler_collapsible_area_text', |
danielebarchiesi@0 | 19 ), |
danielebarchiesi@0 | 20 ); |
danielebarchiesi@0 | 21 } |
danielebarchiesi@0 | 22 </pre> |
danielebarchiesi@0 | 23 |
danielebarchiesi@0 | 24 The second step is to write this handler. Therefore create a file called yourmodule_handler_collapsible_area_text.inc and |
danielebarchiesi@0 | 25 add it to the .info file of your module. |
danielebarchiesi@0 | 26 |
danielebarchiesi@0 | 27 Then add content to your area file like this: |
danielebarchiesi@0 | 28 <pre> |
danielebarchiesi@0 | 29 class yourmodule_handler_collapsible_area_text extends views_handler_area_text { |
danielebarchiesi@0 | 30 function render($empty = FALSE) { |
danielebarchiesi@0 | 31 // Here you just return a string of your content you want. |
danielebarchiesi@0 | 32 if ($render = parent::render($empty)) { |
danielebarchiesi@0 | 33 $element = array( |
danielebarchiesi@0 | 34 '#type' => 'fieldset', |
danielebarchiesi@0 | 35 '#title' => t('Title'), |
danielebarchiesi@0 | 36 '#value' => $render, |
danielebarchiesi@0 | 37 ); |
danielebarchiesi@0 | 38 $output = theme('fieldset', $element); |
danielebarchiesi@0 | 39 return $output; |
danielebarchiesi@0 | 40 } |
danielebarchiesi@0 | 41 } |
danielebarchiesi@0 | 42 } |
danielebarchiesi@0 | 43 </pre> |
danielebarchiesi@0 | 44 |
danielebarchiesi@0 | 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 :) |