function _views_bulk_operations_rules_get_field in Views Bulk Operations (VBO) 7.3
Helper function that loads, builds and executes the specified view, then returns its VBO field.
Parameters
$view_target: A string in the format "$view_name|$display_name".
$args: Arguments that should be passed to the View.
Return value
The VBO field. Contains a reference to the View.
3 calls to _views_bulk_operations_rules_get_field()
- views_bulk_operations_action_load_id_list in ./
views_bulk_operations.rules.inc - The 'views_bulk_operations_action_views_load_id_list' action.
- views_bulk_operations_action_load_list in ./
views_bulk_operations.rules.inc - The 'views_bulk_operations_action_views_load_list' action.
- views_bulk_operations_condition_result_count in ./
views_bulk_operations.rules.inc - The 'views_bulk_operations_condition_result_count' condition.
File
- ./
views_bulk_operations.rules.inc, line 271 - Views Bulk Operations conditions and actions for Rules.
Code
function _views_bulk_operations_rules_get_field($view_target, $args) {
$views =& drupal_static(__FUNCTION__);
$views_settings = explode('|', $view_target);
$view_name = $views_settings[0];
$display_name = $views_settings[1];
// Create an array of arguments.
$view_arguments = explode("\n", $args);
$view_arguments = array_map('trim', $view_arguments);
$view_arguments = array_filter($view_arguments, 'strlen');
// Append the filtered list of arguments to $views_target, so that the correct
// View is fetched from cache.
if (!empty($view_arguments)) {
$view_target .= '|' . implode('&', $view_arguments);
}
// Don't execute the requested View more than once in a single page request.
if (isset($views[$view_target])) {
$vbo = _views_bulk_operations_get_field($views[$view_target]);
return $vbo;
}
// Load the view and set the properties.
$view = views_get_view($view_name);
$view
->set_display($display_name);
$view
->set_arguments($view_arguments);
$view
->build();
$vbo = _views_bulk_operations_get_field($view);
// Unset every field except the VBO one (which holds the entity id).
// That way the performance hit becomes much smaller, because there is no
// chance of views_handler_field_field::post_execute() firing entity_load().
foreach ($view->field as $field_name => $field) {
if ($field_name != $vbo->options['id']) {
unset($view->field[$field_name]);
}
}
$view
->execute($view->current_display);
// Save the view in the static cache.
$views[$view_target] = $view;
return $vbo;
}