You are here

function rb_misc_action_views_load_list in Rules Bonus Pack 7

The 'rb_misc_action_views_load_list' action.

File

./rb_misc.rules.inc, line 570
Miscellaneous conditions and actions for Rules.

Code

function rb_misc_action_views_load_list($view, $args) {

  // Prepare some data about the view.
  $views_settings = explode('|', $view);
  $view_name = $views_settings[0];
  $display_name = $views_settings[1];
  $view_arguments = explode("\r", $args);

  // Load the view and set the properties.
  $view = views_get_view($view_name);
  $view
    ->set_display($display_name);
  $view
    ->set_arguments($view_arguments);
  $view
    ->set_items_per_page(0);
  $view
    ->execute();

  // Rules expects a list of fully loaded nodes, so we have to loop through this
  // list and finally do a heck of a lot of node loads. :-(
  $nids = array();
  foreach ($view->result as $row) {
    $nids[] = $row->nid;
  }

  // Load the nodes, and return them.
  return array(
    'node_list' => node_load_multiple($nids),
  );
}