function drush_views_execute

8.0.x views.d8.drush.inc drush_views_execute($view_name, $display_id = NULL)
7.x views.d8.drush.inc drush_views_execute($view_name, $display_id = NULL)

Drush views execute command.

File

commands/core/views.d8.drush.inc, line 265
Drush integration for views.

Code

function drush_views_execute($view_name, $display_id = NULL) {
  $args = func_get_args();
  $view_args = array();

  // If it's more than 2, we have arguments. A display has to be specified in
  // that case.
  if (count($args) > 2) {
    $view_args = array_slice($args, 2);
  }

  if (!$view = Views::getView($view_name)) {
    return drush_set_error(dt('View: "@view" not found.', array('@view' => $view_name)));
  }

  // Set the display and execute the view.
  $view->setDisplay($display_id);
  $view->preExecute($view_args);
  $view->execute();

  if (drush_get_option('count', FALSE)) {
    drush_set_default_outputformat('string');
    return count($view->result);
  }
  elseif (!empty($view->result)) {
    if (drush_get_option('rendered', FALSE)) {
      drush_set_default_outputformat('string');
      // Don't show admin links in markup by default.
      $view->hide_admin_links = !drush_get_option('show-admin-links', FALSE);
      $output = $view->preview();
      return drupal_render($output);

    }
    else {
      return $view->result;
    }
  }
  else {
    drush_log(dt('No results returned for this view.'), LogLevel::WARNING);
    return NULL;
  }
}