api-handler-area.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. <h3>Requirements</h3>
  3. 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
  4. how to extend views.
  5. <h3>Create your own area handler</h3>
  6. The first step is to tell views: Hey i want to add a new area handler.
  7. Therefore you have to implement hook_views_data and add a new one. For example:
  8. <pre>
  9. function yourmodule_views_data() {
  10. $data['views']['collapsible_area'] = array(
  11. 'title' =&gt; t('Collabsible Text area'),
  12. 'help' =&gt; t('Provide collabsible markup text for the area.'),
  13. 'area' =&gt; array(
  14. 'handler' =&gt; 'yourmodule_handler_collapsible_area_text',
  15. ),
  16. );
  17. }
  18. </pre>
  19. The second step is to write this handler. Therefore create a file called yourmodule_handler_collapsible_area_text.inc and
  20. add it to the .info file of your module.
  21. Then add content to your area file like this:
  22. <pre>
  23. class yourmodule_handler_collapsible_area_text extends views_handler_area_text {
  24. function render($empty = FALSE) {
  25. // Here you just return a string of your content you want.
  26. if ($render = parent::render($empty)) {
  27. $element = array(
  28. '#type' =&gt; 'fieldset',
  29. '#title' =&gt; t('Title'),
  30. '#value' =&gt; $render,
  31. );
  32. $output = theme('fieldset', $element);
  33. return $output;
  34. }
  35. }
  36. }
  37. </pre>
  38. 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 :)