function _views_drush_op

8.0.x views.d8.drush.inc _views_drush_op($op = '', array $view_names = array())
7.x views.d8.drush.inc _views_drush_op($op = '', array $view_names = array())

Perform operations on view objects.

Parameters

string $op: The operation to perform.

array $view_names: An array of view names to load and perform this operation on.

2 calls to _views_drush_op()
drush_views_disable in commands/core/views.d8.drush.inc
Drush views disable command.
drush_views_enable in commands/core/views.d8.drush.inc
Drush views enable command.

File

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

Code

function _views_drush_op($op = '', array $view_names = array()) {
  $op_types = _views_drush_op_types();
  if (!in_array($op, array_keys($op_types))) {
    return drush_set_error(dt('Invalid op type'));
  }

  $view_names = MapArray::copyValuesToKeys($view_names);

  if ($views = Drupal::entityManager()->getStorageController('view')->loadMultiple($view_names)) {
    foreach ($views as $view) {
      $tokens = array(
        '@view' => $view->id(),
        '@action' => $op_types[$op]['action'],
      );

      if ($op_types[$op]['validate']($view)) {
        $function = 'views_' . $op . '_view';
        drush_op($function, $view);
        drush_log(dt('View: @view has been @action', $tokens), LogLevel::SUCCESS);
      }
      else {
        drush_log(dt('View: @view is already @action', $tokens), LogLevel::NOTICE);
      }
      // Remove this view from the viewnames input list.
      unset($view_names[$view->id()]);
    }

    return $views;
  }
  else {
    drush_set_error(dt('No views have been loaded'));
  }

  // If we have some unmatched/leftover view names that weren't loaded.
  if (!empty($view_names)) {
    foreach ($view_names as $viewname) {
      drush_log(dt('View: @view could not be found.', array('@view' => $viewname)), LogLevel::ERROR);
    }
  }

}