api-handler-area.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. return $data;
  18. }
  19. </pre>
  20. The second step is to write this handler. Therefore create a file called yourmodule_handler_collapsible_area_text.inc and
  21. add it to the .info file of your module.
  22. Then add content to your area file like this:
  23. <pre>
  24. class yourmodule_handler_collapsible_area_text extends views_handler_area_text {
  25. function render($empty = FALSE) {
  26. // Here you just return a string of your content you want.
  27. if ($render = parent::render($empty)) {
  28. $element = array(
  29. '#type' =&gt; 'fieldset',
  30. '#title' =&gt; t('Title'),
  31. '#value' =&gt; $render,
  32. );
  33. $output = theme('fieldset', $element);
  34. return $output;
  35. }
  36. }
  37. }
  38. </pre>
  39. 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 :)