Tag Archives: Views

Drupal 7 – Export data using Views data export module with Drush command

Yesterday we talked about exporting data using the Views data export module.
Drupal 7 – Export view data CSV, XML, XLS by Views data export module

The module also provides a Drush command such that you can run the export command in the server which is convenient for backend integration.

The following command is stated in the project page.

  • drush views-data-export [view-name] [display-id] [output-file]

Continue reading

Drupal 7 – Render a view with contextual filter argument programmatically

Some days ago, i write a blog post about how to render a Drupal 7 block programmatically.
Drupal 7 – Render a Block programmatically

If the block is created by Views, there is a simpler solution provided by the Views API. And we can also pass the contextual filter argument too.

print views_embed_view(<view machine name>, <display id>, <arg 1>);


Done =)

Reference: Outputting a Drupal 7 View programmatically with Contextual Filters (arguments)

Drupal 7 – Render Views Exposed Filter programmatically

Update at 2014-09-18: An simpler way to do that is to enable the Exposed form in block in the view settings and then render the block as suggested by plano.com.

The following piece of code render the Views Exposed Filter.

$view = views_get_view('<view name>');
$display_id = 'page';
$form_state = array(
  'view' => $view,
  'display' => $view->display_handler->display,
  'exposed_form_plugin' => $view->display_handler->get_plugin('exposed_form'),
  'method' => 'get',
  'rerender' => TRUE,
  'no_redirect' => TRUE,
$form = drupal_build_form('views_exposed_form', $form_state);
print drupal_render($form);


Done =)


Drupal 7 – Update multiple nodes at once in a Views

Sometimes we may want to update multiple nodes at once. Views Bulk Operations may help if you want to set the same value for a field of multiple nodes. But if you want to set different values among a set of nodes, then Views Bulk Operations could not help.

In Drupal 6, the Editview module may help but unfortunately there is no Drupal 7 version. An alternative solution could be done by editablefields module.

1. Download and enable the module. (I used the 7.x-1.x-dev version)

2. Create a view with table format. (This is not necessary but better user interface)
Continue reading

Drupal 7 – Customize the exposed filter selection list

Yesterday we have talked about how to use selection list for selecting Entity reference in Views exposed filter.
Drupal 7 – Selection list for Entity reference in Views exposed filter

Now i want to have more control on the selection list. For example, i have a content type called competition and i want to limit the number of options in the Entity reference selection list. In this case, we have to create a custom module and alter the views_exposed_form.
Continue reading