views_ui.module

Provide structure for the administrative interface to Views.

File

drupal/core/modules/views/views_ui/views_ui.module
View source
<?php

/**
 * @file
 * Provide structure for the administrative interface to Views.
 */
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\Core\Entity\View;
use Drupal\views_ui\ViewUI;
use Drupal\views\Analyzer;
use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\HttpFoundation\JsonResponse;

/**
 * Implements hook_menu().
 */
function views_ui_menu() {
  $items = array();

  // Minor code reduction technique.
  $base = array(
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer views',
    ),
    'file' => 'admin.inc',
  );

  // Set up the base for AJAX callbacks.
  $ajax_base = array(
    'page callback' => 'views_ui_ajax_callback',
    'page arguments' => array(
      4,
      5,
    ),
    'type' => MENU_CALLBACK,
  ) + $base;

  // Top-level Views module pages (not tied to a particular View).
  $items['admin/structure/views/add'] = array(
    'title' => 'Add new view',
    'page callback' => 'views_ui_add_page',
    'type' => MENU_LOCAL_ACTION,
  ) + $base;
  $items['admin/structure/views'] = array(
    'title' => 'Views',
    'description' => 'Manage customized lists of content.',
    'page callback' => 'views_ui_list_page',
  ) + $base;
  $items['admin/structure/views/list'] = array(
    'title' => 'List',
    'weight' => -10,
    'type' => MENU_DEFAULT_LOCAL_TASK,
  ) + $base;
  $items['admin/structure/views/view/%views_ui_cache/clone'] = array(
    'title callback' => 'views_ui_clone_title',
    'title arguments' => array(
      4,
    ),
    'page callback' => 'entity_get_form',
    'page arguments' => array(
      4,
      'clone',
    ),
    'type' => MENU_CALLBACK,
  ) + $base;
  $items['admin/structure/views/view/%views_ui/enable'] = array(
    'title' => 'Enable a view',
  ) + $ajax_base;
  $items['admin/structure/views/view/%views_ui/disable'] = array(
    'title' => 'Disable a view',
  ) + $ajax_base;
  $items['admin/structure/views/view/%views_ui/delete'] = array(
    'title' => 'Delete a view',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'views_ui_confirm_delete',
      4,
    ),
    'type' => MENU_CALLBACK,
  ) + $base;
  $items['admin/structure/views/settings'] = array(
    'title' => 'Settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'views_ui_admin_settings_basic',
    ),
    'type' => MENU_LOCAL_TASK,
  ) + $base;
  $items['admin/structure/views/settings/basic'] = array(
    'title' => 'Basic',
    'page arguments' => array(
      'views_ui_admin_settings_basic',
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
  ) + $base;
  $items['admin/structure/views/settings/advanced'] = array(
    'title' => 'Advanced',
    'page arguments' => array(
      'views_ui_admin_settings_advanced',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 1,
  ) + $base;

  // The primary Edit View page. Secondary tabs for each Display are added in
  // views_ui_menu_local_tasks_alter().
  $items['admin/structure/views/view/%views_ui_cache'] = array(
    'title callback' => 'views_ui_edit_page_title',
    'title arguments' => array(
      4,
    ),
    'page callback' => 'views_ui_edit_page',
    'page arguments' => array(
      4,
    ),
  ) + $base;
  $items['admin/structure/views/view/%views_ui_cache/edit'] = array(
    'title' => 'Edit view',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    'weight' => -10,
    'theme callback' => 'ajax_base_page_theme',
  ) + $base;
  $items['admin/structure/views/view/%views_ui_cache/edit/%/ajax'] = array(
    'page callback' => 'views_ui_ajax_get_form',
    'page arguments' => array(
      'views_ui_edit_form',
      4,
      6,
    ),
    'delivery callback' => 'ajax_deliver',
    'theme callback' => 'ajax_base_page_theme',
    'type' => MENU_CALLBACK,
  ) + $base;
  $items['admin/structure/views/view/%views_ui_cache/preview/%'] = array(
    'page callback' => 'views_ui_build_preview',
    'page arguments' => array(
      4,
      6,
    ),
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
  ) + $base;
  $items['admin/structure/views/view/%views_ui_cache/preview/%/ajax'] = array(
    'page callback' => 'views_ui_build_preview',
    'page arguments' => array(
      4,
      6,
    ),
    'delivery callback' => 'ajax_deliver',
    'theme callback' => 'ajax_base_page_theme',
    'type' => MENU_CALLBACK,
  ) + $base;

  // Additional pages for acting on a View.
  $items['admin/structure/views/view/%views_ui_cache/break-lock'] = array(
    'title' => 'Break lock',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'views_ui_break_lock_confirm',
      4,
    ),
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
  ) + $base;

  // NoJS/AJAX callbacks that can use the default Views AJAX form system.
  $items['admin/structure/views/nojs/%/%views_ui_cache'] = array(
    'page callback' => 'views_ui_ajax_form',
    'page arguments' => array(
      FALSE,
      4,
      5,
    ),
    'type' => MENU_CALLBACK,
  ) + $base;
  $items['admin/structure/views/ajax/%/%views_ui_cache'] = array(
    'page callback' => 'views_ui_ajax_form',
    'page arguments' => array(
      TRUE,
      4,
      5,
    ),
    'delivery callback' => 'ajax_deliver',
    'type' => MENU_CALLBACK,
  ) + $base;
  $items['admin/structure/views/nojs/preview/%views_ui_cache/%'] = array(
    'page callback' => 'views_ui_preview',
    'page arguments' => array(
      5,
      6,
    ),
  ) + $base;
  $items['admin/structure/views/ajax/preview/%views_ui_cache/%'] = array(
    'page callback' => 'views_ui_preview',
    'page arguments' => array(
      5,
      6,
    ),
    'delivery callback' => 'ajax_deliver',
  ) + $base;

  // Autocomplete callback for tagging a View.
  // Views module uses admin/views/... instead of admin/structure/views/... for
  // autocomplete paths, so be consistent with that.
  // @todo Change to admin/structure/views/... when the change can be made to
  //   Views module as well.
  $items['admin/views/ajax/autocomplete/tag'] = array(
    'page callback' => 'views_ui_autocomplete_tag',
    'type' => MENU_CALLBACK,
  ) + $base;

  // A page in the Reports section to show usage of fields in all views
  $items['admin/reports/fields/list'] = array(
    'title' => 'List',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['admin/reports/fields/views-fields'] = array(
    'title' => 'Used in views',
    'description' => 'Overview of fields used in all views.',
    'page callback' => 'views_ui_field_list',
    'type' => MENU_LOCAL_TASK,
    'weight' => 0,
  ) + $base;

  // A page in the Reports section to show usage of plugins in all views.
  $items['admin/reports/views-plugins'] = array(
    'title' => 'Views plugins',
    'description' => 'Overview of plugins used in all views.',
    'page callback' => 'views_ui_plugin_list',
  ) + $base;
  return $items;
}

/**
 * Implements hook_theme().
 */
function views_ui_theme() {
  $path = drupal_get_path('module', 'views_ui');
  return array(
    // edit a view
    'views_ui_display_tab_setting' => array(
      'variables' => array(
        'description' => '',
        'link' => '',
        'settings_links' => array(),
        'overridden' => FALSE,
        'defaulted' => FALSE,
        'description_separator' => TRUE,
        'class' => array(),
      ),
      'template' => 'views-ui-display-tab-setting',
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    'views_ui_display_tab_bucket' => array(
      'render element' => 'element',
      'template' => 'views-ui-display-tab-bucket',
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    'views_ui_edit_item' => array(
      'variables' => array(
        'type' => NULL,
        'view' => NULL,
        'display' => NULL,
        'no_fields' => FALSE,
      ),
      'template' => 'views-ui-edit-item',
      'path' => "{$path}/theme",
    ),
    'views_ui_rearrange_form' => array(
      'render element' => 'form',
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    'views_ui_rearrange_filter_form' => array(
      'render element' => 'form',
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    'views_ui_expose_filter_form' => array(
      'render element' => 'form',
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    // list views
    'views_ui_view_info' => array(
      'variables' => array(
        'view' => NULL,
        'base' => NULL,
      ),
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    // Group of filters.
    'views_ui_build_group_filter_form' => array(
      'render element' => 'form',
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    // tab themes
    'views_tabset' => array(
      'variables' => array(
        'tabs' => NULL,
      ),
    ),
    'views_tab' => array(
      'variables' => array(
        'body' => NULL,
      ),
    ),
    'views_ui_reorder_displays_form' => array(
      'render element' => 'form',
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    // On behalf of a plugin
    'views_ui_style_plugin_table' => array(
      'render element' => 'form',
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    // When previewing a view.
    'views_ui_view_preview_section' => array(
      'variables' => array(
        'view' => NULL,
        'section' => NULL,
        'content' => NULL,
        'links' => '',
      ),
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
    // Generic container wrapper, to use instead of theme_container when an id
    // is not desired.
    'views_ui_container' => array(
      'render element' => 'element',
      'path' => "{$path}/theme",
      'file' => 'theme.inc',
    ),
  );
}

/**
 * Implements hook_library_info().
 */
function views_ui_library_info() {
  $libraries = array();
  $libraries['views_ui.admin'] = array(
    'title' => 'Views UI ADMIN',
    'version' => VERSION,
    'js' => array(
      drupal_get_path('module', 'views_ui') . '/js/views-admin.js' => array(
        'group' => JS_DEFAULT,
      ),
    ),
    'dependencies' => array(
      array(
        'system',
        'jquery',
      ),
      array(
        'system',
        'drupal',
      ),
      array(
        'system',
        'drupalSettings',
      ),
      array(
        'system',
        'jquery.once',
      ),
      array(
        'system',
        'jquery.form',
      ),
      array(
        'system',
        'drupal.ajax',
      ),
      array(
        'views',
        'views.ajax',
      ),
    ),
  );
  return $libraries;
}

/**
 * Page title callback for the Edit View page.
 */
function views_ui_edit_page_title(ViewUI $view) {
  module_load_include('inc', 'views_ui', 'admin');
  $bases = views_fetch_base_tables();
  $name = $view
    ->getHumanName();
  if (isset($bases[$view
    ->get('base_table')])) {
    $name .= ' (' . $bases[$view
      ->get('base_table')]['title'] . ')';
  }
  return $name;
}

/**
 * Specialized menu callback to load a view and check its locked status.
 *
 * @param $name
 *   The machine name of the view.
 *
 * @return
 *   The view object, with a "locked" property indicating whether or not
 *   someone else is already editing the view.
 */
function views_ui_cache_load($name) {
  $views_temp_store = drupal_container()
    ->get('user.tempstore')
    ->get('views');
  $view = $views_temp_store
    ->get($name);
  $storage = entity_load('view', $name);
  $original_view = $storage ? new ViewUI($storage) : NULL;
  if (empty($view)) {
    $view = $original_view;
    if (!empty($view)) {

      // Check to see if someone else is already editing this view.
      // Set a flag to indicate that this view is being edited.
      // This flag will be used e.g. to determine whether strings
      // should be localized.
      $view->editing = TRUE;
    }
  }
  else {

    // Keep disabled/enabled status real.
    if ($original_view) {
      $view
        ->set('disabled', $original_view
        ->get('disabled'));
    }
  }
  if (empty($view)) {
    return FALSE;
  }
  $view->locked = $views_temp_store
    ->getMetadata($view
    ->get('name'));
  return $view;
}

/**
 * Specialized cache function to add a flag to our view, include an appropriate
 * include, and cache more easily.
 */
function views_ui_cache_set(ViewUI $view) {
  if (isset($view->locked) && is_object($view->locked) && $view->locked->owner != $GLOBALS['user']->uid) {
    drupal_set_message(t('Changes cannot be made to a locked view.'), 'error');
    return;
  }
  $view->changed = TRUE;

  // let any future object know that this view has changed.
  $executable = $view
    ->get('executable');
  if (isset($executable->current_display)) {

    // Add the knowledge of the changed display, too.
    $view->changed_display[$executable->current_display] = TRUE;
    unset($executable->current_display);
  }

  // Unset handlers; we don't want to write these into the cache
  unset($executable->display_handler);
  unset($executable->default_display);
  $executable->query = NULL;
  $executable->displayHandlers = array();
  drupal_container()
    ->get('user.tempstore')
    ->get('views')
    ->set($view
    ->get('name'), $view);
}

/**
 * Title callback for the views clone form.
 *
 * @param \Drupal\views\ViewExecutable $view
 *   The view to clone.
 */
function views_ui_clone_title(ViewUI $view) {
  return t('Clone of @human_name', array(
    '@human_name' => $view
      ->getHumanName(),
  ));
}

/**
 * Theme preprocess for views-view.tpl.php.
 */
function views_ui_preprocess_views_view(&$vars) {
  $view = $vars['view'];
  if (!empty($view->views_ui_context) && module_exists('contextual')) {
    $view->hide_admin_links = TRUE;
    foreach (array(
      'title',
      'header',
      'exposed',
      'rows',
      'pager',
      'more',
      'footer',
      'empty',
      'attachment_after',
      'attachment_before',
    ) as $section) {
      if (!empty($vars[$section])) {
        $vars[$section] = array(
          '#theme' => 'views_ui_view_preview_section',
          '#view' => $view,
          '#section' => $section,
          '#content' => is_array($vars[$section]) ? drupal_render($vars[$section]) : $vars[$section],
          '#theme_wrappers' => array(
            'views_ui_container',
          ),
          '#attributes' => array(
            'class' => 'contextual-region',
          ),
        );
        $vars[$section] = drupal_render($vars[$section]);
      }
    }
  }
}

/**
 * Returns contextual links for each handler of a certain section.
 *
 * @TODO
 *   Bring in relationships
 *   Refactor this function to use much stuff of views_ui_edit_form_get_bucket.
 *
 * @param $title
 *   Add a bolded title of this section.
 */
function views_ui_view_preview_section_handler_links(ViewUI $view, $type, $title = FALSE) {
  $display = $view->executable->display_handler->display;
  $handlers = $view->executable->display_handler
    ->getHandlers($type);
  $links = array();
  $types = ViewExecutable::viewsHandlerTypes();
  if ($title) {
    $links[$type . '-title'] = array(
      'title' => $types[$type]['title'],
    );
  }
  foreach ($handlers as $id => $handler) {
    $field_name = $handler
      ->adminLabel(TRUE);
    $links[$type . '-edit-' . $id] = array(
      'title' => t('Edit @section', array(
        '@section' => $field_name,
      )),
      'href' => "admin/structure/views/nojs/config-item/{$view->get('name')}/{$display['id']}/{$type}/{$id}",
      'attributes' => array(
        'class' => array(
          'views-ajax-link',
        ),
      ),
    );
  }
  $links[$type . '-add'] = array(
    'title' => t('Add new'),
    'href' => "admin/structure/views/nojs/add-item/{$view->get('name')}/{$display['id']}/{$type}",
    'attributes' => array(
      'class' => array(
        'views-ajax-link',
      ),
    ),
  );
  return $links;
}

/**
 * Returns a link to editing a certain display setting.
 */
function views_ui_view_preview_section_display_category_links(ViewUI $view, $type, $title) {
  $display = $view->display_handler->display;
  $links = array(
    $type . '-edit' => array(
      'title' => t('Edit @section', array(
        '@section' => $title,
      )),
      'href' => "admin/structure/views/nojs/display/{$view->get('name')}/{$display['id']}/{$type}",
      'attributes' => array(
        'class' => array(
          'views-ajax-link',
        ),
      ),
    ),
  );
  return $links;
}

/**
 * Returns all contextual links for the main content part of the view.
 */
function views_ui_view_preview_section_rows_links(ViewUI $view) {
  $display = $view->executable->display_handler->display;
  $links = array();
  $links = array_merge($links, views_ui_view_preview_section_handler_links($view, 'filter', TRUE));
  $links = array_merge($links, views_ui_view_preview_section_handler_links($view, 'field', TRUE));
  $links = array_merge($links, views_ui_view_preview_section_handler_links($view, 'sort', TRUE));
  $links = array_merge($links, views_ui_view_preview_section_handler_links($view, 'argument', TRUE));
  $links = array_merge($links, views_ui_view_preview_section_handler_links($view, 'relationship', TRUE));
  return $links;
}

/**
 * Implements hook_views_plugins_display_alter().
 */
function views_ui_views_plugins_display_alter(&$plugins) {

  // Attach contextual links to each display plugin. The links will point to
  // paths underneath "admin/structure/views/view/{$view->get('name')}" (i.e., paths
  // for editing and performing other contextual actions on the view).
  foreach ($plugins as &$display) {
    $display['contextual links']['views_ui'] = array(
      'parent path' => 'admin/structure/views/view',
      'argument properties' => array(
        'name',
      ),
    );
  }
}

/**
 * Implements hook_contextual_links_view_alter().
 */
function views_ui_contextual_links_view_alter(&$element, $items) {

  // Remove contextual links from being rendered, when so desired, such as
  // within a View preview.
  if (views_ui_contextual_links_suppress()) {
    $element['#links'] = array();
  }
  elseif (!empty($element['#links']['views-ui-edit']) && !empty($element['#element']['#views_contextual_links_info']['views_ui']['view_display_id'])) {
    $display_id = $element['#element']['#views_contextual_links_info']['views_ui']['view_display_id'];
    $element['#links']['views-ui-edit']['href'] .= '/' . $display_id;
  }
}

/**
 * Sets a static variable for controlling whether contextual links are rendered.
 *
 * @see views_ui_contextual_links_view_alter()
 */
function views_ui_contextual_links_suppress($set = NULL) {
  $suppress =& drupal_static(__FUNCTION__);
  if (isset($set)) {
    $suppress = $set;
  }
  return $suppress;
}

/**
 * Increments the views_ui_contextual_links_suppress() static variable.
 *
 * When this function is added to the #pre_render of an element, and
 * 'views_ui_contextual_links_suppress_pop' is added to the #post_render of the
 * same element, then all contextual links within the element and its
 * descendants are suppressed from being rendered. This is used, for example,
 * during a View preview, when it is not desired for nodes in the Views result
 * to have contextual links.
 *
 * @see views_ui_contextual_links_suppress_pop()
 */
function views_ui_contextual_links_suppress_push() {
  views_ui_contextual_links_suppress((int) views_ui_contextual_links_suppress() + 1);
}

/**
 * Decrements the views_ui_contextual_links_suppress() static variable.
 *
 * @see views_ui_contextual_links_suppress_push()
 */
function views_ui_contextual_links_suppress_pop() {
  views_ui_contextual_links_suppress((int) views_ui_contextual_links_suppress() - 1);
}

/**
 * Menu callback; handles AJAX form submissions similar to ajax_form_callback(), but can be used for uncached forms.
 *
 * ajax_form_callback(), the menu callback for the system/ajax path, requires
 * the form to be retrievable from the form cache, because it lacks a trusted
 * $form_id argument with which to call drupal_retrieve_form(). When AJAX is
 * wanted on a non-cacheable form, #ajax['path'] can be set to a path whose
 * menu router item's 'page callback' is this function, and whose
 * 'page arguments' is the form id, optionally followed by additional build
 * arguments, as expected by drupal_get_form().
 *
 * The same caution must be used when defining a hook_menu() entry with this
 * page callback as is used when defining a hook_menu() entry with the
 * 'drupal_get_form' page callback: a 'page arguments' must be specified with a
 * literal value as the first argument, because $form_id determines which form
 * builder function gets called, so must be safe from user tampering.
 *
 * @see drupal_get_form()
 * @see ajax_form_callback()
 * @see http://drupal.org/node/774876
 */
function views_ui_ajax_get_form($form_id) {

  // @see ajax_get_form()
  $form_state = array(
    'no_redirect' => TRUE,
  );
  $form_state['rebuild_info']['copy']['#build_id'] = TRUE;
  $form_state['rebuild_info']['copy']['#action'] = TRUE;

  // @see drupal_get_form()
  $args = func_get_args();
  array_shift($args);
  $form_state['build_info']['args'] = $args;
  $form = drupal_build_form($form_id, $form_state);

  // @see ajax_form_callback()
  if (!empty($form_state['triggering_element'])) {
    $callback = $form_state['triggering_element']['#ajax']['callback'];
  }
  if (!empty($callback) && function_exists($callback)) {
    return $callback($form, $form_state);
  }
}

/**
 * This is part of a patch to address a jQueryUI bug.  The bug is responsible
 * for the inability to scroll a page when a modal dialog is active. If the content
 * of the dialog extends beyond the bottom of the viewport, the user is only able
 * to scroll with a mousewheel or up/down keyboard keys.
 *
 * @see http://bugs.jqueryui.com/ticket/4671
 * @see https://bugs.webkit.org/show_bug.cgi?id=19033
 * @see /js/jquery.ui.dialog.patch.js
 * @see /js/jquery.ui.dialog.min.js
 *
 * The javascript patch overwrites the $.ui.dialog.overlay.events object to remove
 * the mousedown, mouseup and click events from the list of events that are bound
 * in $.ui.dialog.overlay.create.
 */
function views_ui_library_alter(&$libraries, $module) {
  if ($module == 'system' && isset($libraries['jquery.ui.dialog'])) {
    if (version_compare($libraries['jquery.ui.dialog']['version'], '1.7.2', '>=')) {
      $libraries['jquery.ui.dialog']['js'][drupal_get_path('module', 'views') . '/js/jquery.ui.dialog.patch.js'] = array();
    }
  }
}

/**
 * Implements hook_views_analyze().
 *
 * This is the basic views analysis that checks for very minimal problems.
 * There are other analysis tools in core specific sections, such as
 * node.views.inc as well.
 */
function views_ui_views_analyze($view) {
  $ret = array();

  // Check for something other than the default display:
  if (count($view->displayHandlers) < 2) {
    $ret[] = Analyzer::formatMessage(t('This view has only a default display and therefore will not be placed anywhere on your site; perhaps you want to add a page or a block display.'), 'warning');
  }

  // You can give a page display the same path as an alias existing in the
  // system, so the alias will not work anymore. Report this to the user,
  // because he probably wanted something else.
  foreach ($view->displayHandlers as $display) {
    if (empty($display)) {
      continue;
    }
    if ($display
      ->hasPath() && ($path = $display
      ->getOption('path'))) {
      $normal_path = drupal_container()
        ->get('path.alias_manager')
        ->getSystemPath($path);
      if ($path != $normal_path) {
        $ret[] = Analyzer::formatMessage(t('You have configured display %display with a path which is an path alias as well. This might lead to unwanted effects so better use an internal path.', array(
          '%display' => $display['display_title'],
        )), 'warning');
      }
    }
  }
  return $ret;
}

/**
 * Truncate strings to a set length and provide a ... if they truncated.
 *
 * This is often used in the UI to ensure long strings fit.
 */
function views_ui_truncate($string, $length) {
  if (drupal_strlen($string) > $length) {
    $string = drupal_substr($string, 0, $length);
    $string .= '...';
  }
  return $string;
}

/**
 * Magic load function. Wrapper to load a view.
 */
function views_ui_load($name) {
  return views_get_view($name);
}

/**
 * Page callback: Calls a method on a view and reloads the listing page.
 *
 * @param Drupal\views\ViewExectuable $view
 *   The config entity being acted upon.
 * @param string $op
 *   The operation to perform, e.g., 'enable' or 'disable'.
 *
 * @return mixed
 *   Either returns the listing page as JSON, or calls drupal_goto() to
 *   redirect back to the listing page.
 */
function views_ui_ajax_callback(ViewExecutable $view, $op) {

  // Perform the operation.
  $view->storage
    ->{$op}();

  // If the request is via AJAX, return the rendered list as JSON.
  if (drupal_container()
    ->get('request')->request
    ->get('js')) {
    $list = entity_list_controller('view')
      ->render();
    $commands = array(
      ajax_command_replace('#views-entity-list', drupal_render($list)),
    );
    return new JsonResponse(ajax_render($commands));
  }
  else {
    $entity_info = entity_get_info('view');
    drupal_goto('admin/structure/views');
  }
}

/**
 * Form constructor for the View deletion form.
 *
 * @param \Drupal\views\ViewExectuable $view
 *   The View being deleted.
 *
 * @see views_ui_confirm_delete_submit()
 */
function views_ui_confirm_delete($form, &$form_state, ViewExecutable $view) {
  $form['view'] = array(
    '#type' => 'value',
    '#value' => $view,
  );
  return confirm_form($form, t('Are you sure you want to delete the %name view?', array(
    '%name' => $view->storage
      ->getHumanName(),
  )), 'admin/structure/views', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
}

/**
 * Form submission handler for views_ui_confirm_delete().
 */
function views_ui_confirm_delete_submit($form, &$form_state) {
  $form_state['values']['view']->storage
    ->delete();
  $form_state['redirect'] = 'admin/structure/views';
}

/**
 * Page callback: Lists all of the views.
 *
 * @return array
 *   A render array for a page containing a list of views.
 *
 * @see views_ui_menu()
 */
function views_ui_list_page() {
  return entity_list_controller('view')
    ->render();
}

Functions

Namesort descending Description
views_ui_ajax_callback Page callback: Calls a method on a view and reloads the listing page.
views_ui_ajax_get_form Menu callback; handles AJAX form submissions similar to ajax_form_callback(), but can be used for uncached forms.
views_ui_cache_load Specialized menu callback to load a view and check its locked status.
views_ui_cache_set Specialized cache function to add a flag to our view, include an appropriate include, and cache more easily.
views_ui_clone_title Title callback for the views clone form.
views_ui_confirm_delete Form constructor for the View deletion form.
views_ui_confirm_delete_submit Form submission handler for views_ui_confirm_delete().
views_ui_contextual_links_suppress Sets a static variable for controlling whether contextual links are rendered.
views_ui_contextual_links_suppress_pop Decrements the views_ui_contextual_links_suppress() static variable.
views_ui_contextual_links_suppress_push Increments the views_ui_contextual_links_suppress() static variable.
views_ui_contextual_links_view_alter Implements hook_contextual_links_view_alter().
views_ui_edit_page_title Page title callback for the Edit View page.
views_ui_library_alter This is part of a patch to address a jQueryUI bug. The bug is responsible for the inability to scroll a page when a modal dialog is active. If the content of the dialog extends beyond the bottom of the viewport, the user is only able to scroll with a…
views_ui_library_info Implements hook_library_info().
views_ui_list_page Page callback: Lists all of the views.
views_ui_load Magic load function. Wrapper to load a view.
views_ui_menu Implements hook_menu().
views_ui_preprocess_views_view Theme preprocess for views-view.tpl.php.
views_ui_theme Implements hook_theme().
views_ui_truncate Truncate strings to a set length and provide a ... if they truncated.
views_ui_views_analyze Implements hook_views_analyze().
views_ui_views_plugins_display_alter Implements hook_views_plugins_display_alter().
views_ui_view_preview_section_display_category_links Returns a link to editing a certain display setting.
views_ui_view_preview_section_handler_links Returns contextual links for each handler of a certain section.
views_ui_view_preview_section_rows_links Returns all contextual links for the main content part of the view.