Main menu

Drupal 7: Programmatically inject an arbitrary content into the view

Published by dnovikov on Fri, 04/27/2012 - 11:12

If you want to add something to the view, use

<?php
$view
->add_item
?>
method. It can be a form for example:

<?php
/**
 * Implements hook_views_pre_build().
 */
function mymodule_views_pre_build(&$view) {
  if (
$view->name == 'my_view') {
   
$form = drupal_get_form('mymodule_form');
   
$header = drupal_render($form);
   
$view->add_item('default', 'header', 'views', 'area', array('content' => $header, 'format' => 'full_html'));
  }
}
?>

Comments

wonderful post, very informative. I'm wondering why the opposite specialists of this sector don't understand this.

You should continue your writing. I am sure,
you've a huge readers' base already!

Hi there to every one, as I am really keen of reading this webpage's post to be updated regularly. It carries fastidious material.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.