You are here

views_ui.module in Views (for Drupal 7) 5

Same filename and directory in other branches
  1. 6.3 views_ui.module
  2. 6.2 views_ui.module
  3. 7.3 views_ui.module

File

views_ui.module
View source
<?php

// ---------------------------------------------------------------------------
// Drupal Hooks

/*
 * Implementation of hook_help()
 */
function views_ui_help($section) {
  switch ($section) {
    case 'admin/help#views_ui':
      return _views_ui_help_add();
    case 'admin/build/views/import':
      return t('You may import a view by cut-and-pasting the results of an export view. If the import is successful you will be taken to the Add View page with all of the settings of the imported view..');
    case 'admin/build/views':
      return t('This screen shows all of the views that are currently defined in your system. The default views are provided by Views and other modules and are automatically available. If a customized view of the same name exists, it will be used in place of a default view.');
  }
  if (!strncmp($section, 'admin/build/views', 11)) {
    switch (arg(2)) {
      case 'add':
      case 'edit':
        return t('Please see !s or the views documentation on drupal.org for help here.', array(
          '!s' => l(t('the views help page'), 'admin/help/views_ui'),
        ));
      case 'export':
        return t('You may cut & paste this view into an import function on another system. The view will only work if all modules required by the view are installed on the target location.');
    }
  }
}

/*
 * Because the add/edit page is kind of complicated.
 */
function _views_ui_help_add() {
  $output = t('<p>A view retrieves some number of nodes from the database and displays them in a variety of formats.</p>');
  $output .= t("<h3>View Types</h3>\n    <dl>\n      <dt><em>List View</em></dt><dd>A List View provides the data for each node retrieved in the form of an unordered list. Each item in the Fields section will be displayed; the Title will be displayed as a label. The order the items appear in the Fields list is the order the items will appear in the output. Leaving the title blank will cause the field to appear with no label (which is desirable in lists that just display titles, for example).</dd>\n      <dt><em>Table View</em></dt><dd>A Table View provides the data for each node as one row of a table. The Fields selected in the Fields list will be displayed in the order they are listed. The title column will be shown in the header. If you set the field to 'sortable' then the header will be click-sortable; be careful here as click-sorts will be processed after built-in sort criteria, and built-in sort criteria can easily make click-sorts invalid. If using click-sorts, choose a field to be the default sort; otherwise the first field presented will be the default sort.</dd>\n      <dt><em>Teaser List</em></dt><dd>A Teaser List will simply present the teaser of each node retrieved.</dd>\n      <dt><em>Full Nodes</em></dt><dd>This will show the full content of each node retrieved.</dd>\n      <dt><em>Random Teaser</em></dt><dd>This will show a single random teaser.</dd>\n      <dt><em>Random Node</em></dt><dd>This will show a single random node's full view.</dd>\n    </dl>");
  views_load_cache();
  $output .= t("<h3>Fields</h3>\n");
  $output .= t("<p>When using List or Table view, it is necessary to choose which fields will be displayed to the user.</p><dl>\n");
  $fields = _views_get_fields();
  foreach ($fields as $field) {
    $output .= "<dt><em>{$field['name']}</em></dt><dd>{$field['help']}</dd>\n";
  }
  $output .= "</dl>\n";
  $output .= t("<h3>Arguments</h3>\n");
  $output .= t("<p>Arguments can be passed to the View through the URL, in order to create views that are configurable by the user. This is very useful to create views for taxonomy, or to sort by user. When using arguments, substitution is performed on the title. %1 will represent argument 1, %2 will represent argument 2. Each argument has a title field; this title is used if providing a summary view (which can matter because the argument is missing which could result in confusing phrases such as 'view for')</p><dl>\n");
  $arguments = _views_get_arguments();
  foreach ($arguments as $argument) {
    $output .= "<dt><em>{$argument['name']}</em></dt><dd>{$argument['help']}</dd>\n";
  }
  $output .= "</dl>\n";
  $output .= t("<h3>Filters</h3>\n");
  $output .= t("<p>Views may be filtered to restrict the view on a number of criteria.</p><dl>\n");
  $filters = _views_get_filters();
  foreach ($filters as $filter) {
    $output .= "<dt><em>{$filter['name']}</em></dt><dd>{$filter['help']}</dd>\n";
  }
  $output .= "</dl>\n";
  $output .= t("<h3>Sorting Critera</h3>\n");
  $output .= t("<p>The result set may be sorted on any of the following criteria.</p><dl>\n");
  $sorts = _views_get_sorts();
  foreach ($sorts as $sort) {
    $output .= "<dt><em>{$sort['name']}</em></dt><dd>{$sort['help']}</dd>\n";
  }
  $output .= "</dl>\n";
  return $output;
}

/*
 * Implementation of hook_perm()
 */
function views_ui_perm() {
  return array(
    'administer views',
  );
}

/*
 * Implementation of hook_menu()
 */
function views_ui_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/build/views',
      'title' => t('Views'),
      'callback' => 'views_ui_admin_page',
      'access' => user_access('administer views'),
      'description' => t('Views are customized lists of content on your system; they are highly configurable and give you control over how lists of content are presented.'),
      'type' => MENU_NORMAL_ITEM,
    );
    $items[] = array(
      'path' => 'admin/build/views/list',
      'title' => t('List'),
      'callback' => 'views_ui_admin_page',
      'access' => user_access('administer views'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => '-1',
    );
    $items[] = array(
      'path' => 'admin/build/views/add',
      'title' => t('Add'),
      'callback' => 'views_ui_admin_add_page',
      'access' => user_access('administer views'),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/build/views/import',
      'title' => t('Import'),
      'callback' => 'views_ui_admin_import_page',
      'access' => user_access('administer views') && user_access('use PHP for block visibility'),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/build/views/tools',
      'title' => t('Tools'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'views_ui_admin_tools',
      ),
      'access' => user_access('administer views'),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/build/views/delete',
      'title' => t('Edit view'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'views_ui_admin_delete_confirm',
      ),
      'access' => user_access('administer views'),
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/build/views/enable',
      'callback' => 'views_ui_admin_enable_page',
      'access' => user_access('administer views'),
      'type' => MENU_CALLBACK,
    );
    $items[] = array(
      'path' => 'admin/build/views/disable',
      'callback' => 'views_ui_admin_disable_page',
      'access' => user_access('administer views'),
      'type' => MENU_CALLBACK,
    );
  }
  else {
    if (user_access('administer views') && arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'views') {
      $view = views_load_view(arg(3));
      if ($view) {
        views_ui_add_menu_items($items, $view, 'admin/build/views/' . arg(3), TRUE);
      }
    }
  }
  return $items;
}
function views_ui_add_menu_items(&$items, $view, $url, $base = TRUE, $args = array()) {
  if (user_access('administer views')) {
    if ($base) {

      // we also have to add the administrative 'view' of the view in some
      // cases
      $items[] = array(
        'path' => $url,
        'title' => t('View'),
        'callback' => 'views_view_page',
        'callback arguments' => array_merge(array(
          $view->name,
        ), $args),
        'access' => user_access('administer views'),
        'type' => MENU_CALLBACK,
      );
    }
    $items[] = array(
      'path' => "{$url}/view",
      'title' => t('View'),
      'callback' => 'views_page',
      'callback arguments' => array_merge(array(
        $view->name,
      ), $args),
      'access' => user_access('administer views'),
      'weight' => -10,
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
    if (isset($view->is_default)) {
      $items[] = array(
        'path' => "{$url}/add",
        'title' => t('Override'),
        'callback' => 'views_ui_admin_add_page',
        'callback arguments' => array(
          $view->name,
        ),
        'access' => user_access('administer views'),
        'weight' => -5,
        'type' => MENU_LOCAL_TASK,
      );
    }
    else {
      $items[] = array(
        'path' => "{$url}/edit",
        'title' => t('Edit'),
        'callback' => 'views_ui_admin_edit_page',
        'callback arguments' => array(
          $view->name,
        ),
        'access' => user_access('administer views'),
        'weight' => -5,
        'type' => MENU_LOCAL_TASK,
      );
    }
    $items[] = array(
      'path' => "{$url}/export",
      'title' => t('Export'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'views_ui_admin_export_page',
        $view->name,
      ),
      'access' => user_access('administer views'),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => "{$url}/clone",
      'title' => t('Clone'),
      'callback' => 'views_ui_admin_clone_page',
      'callback arguments' => array(
        $view->name,
      ),
      'access' => user_access('administer views'),
      'type' => MENU_LOCAL_TASK,
    );
  }
}

// ---------------------------------------------------------------------------
// Administrative Pages

/*
 * This page lists all system views and provides links to edit them.
 */
function views_ui_admin_page() {
  views_load_cache();
  $numViews = 25;
  drupal_set_title(t('Administer views'));
  $result = pager_query("SELECT vid, name, description, menu_title, page_title, block_title, url, page, menu, block FROM {view_view} ORDER BY name", $numViews);
  while ($view = db_fetch_object($result)) {
    $url = $view->page ? l($view->url, $view->url) : t('No Page View');
    $provides = array();
    if ($view->page) {
      $provides[] = 'Page';
    }
    if ($view->block) {
      $provides[] = 'Block';
    }
    if ($view->menu) {
      $provides[] = 'Menu';
    }
    $items[] = array(
      $view->name,
      filter_xss_admin(views_get_title($view, 'admin')),
      $view->description,
      implode(', ', $provides),
      $url,
      theme('links', array(
        array(
          'title' => t('Edit'),
          'href' => "admin/build/views/{$view->name}/edit",
        ),
        array(
          'title' => t('Export'),
          'href' => "admin/build/views/{$view->name}/export",
        ),
        array(
          'title' => t('Delete'),
          'href' => "admin/build/views/delete/{$view->vid}",
        ),
        array(
          'title' => t('Clone'),
          'href' => "admin/build/views/{$view->name}/clone",
        ),
      )),
    );
  }
  if ($items) {
    $output = theme('table', array(
      t('View'),
      t('Title'),
      t('Description'),
      t('Provides'),
      t('URL'),
      t('Actions'),
    ), $items, array(
      "cellpadding" => "4",
    ), t('Existing Views'));
    $output .= theme('pager', NULL, $numViews);
  }
  else {
    $output .= t('<p>No views have currently been defined.</p>');
  }
  $result = db_query("SELECT name FROM {view_view}");
  while ($view = db_fetch_object($result)) {
    $used[$view->name] = true;
  }
  $output .= t('<p>Below are system default views; if you edit one of these, a view will be created that will override any system use of the view.</p>');
  $items = array();
  $default_views = _views_get_default_views();
  $views_status = variable_get('views_defaults', array());
  foreach ($default_views as $view) {
    $url = $view->page ? l($view->url, $view->url) : t('No Page View');
    if ($used[$view->name]) {
      $status = t('Overridden');
    }
    else {
      if (isset($views_status[$view->name])) {
        if ($views_status[$view->name] == 'enabled') {
          $status = t('Enabled');
        }
        else {
          $status = t('Disabled');
        }
      }
      else {
        if ($view->disabled) {
          $status = t('Disabled');
        }
        else {
          $status = t('Enabled');
        }
      }
    }
    $provides = array();
    if ($view->page) {
      $provides[] = t('Page');
    }
    if ($view->block) {
      $provides[] = t('Block');
    }
    if ($view->menu) {
      $provides[] = t('Menu');
    }
    $links = array();
    $links[] = array(
      'title' => t('Add'),
      'href' => "admin/build/views/add/{$view->name}",
    );
    $token_enable = drupal_get_token('views-enable');
    $token_disable = drupal_get_token('views-disable');
    if ($status == t('Enabled')) {
      $links[] = array(
        'title' => t('Disable'),
        'href' => "admin/build/views/disable/{$view->name}",
        'query' => 'token=' . $token_disable,
      );
    }
    else {
      if ($status == t('Disabled')) {
        $links[] = array(
          'title' => t('Enable'),
          'href' => "admin/build/views/enable/{$view->name}",
          'query' => 'token=' . $token_enable,
        );
      }
    }
    $items[] = array(
      $view->name,
      filter_xss_admin(views_get_title($view, 'menu')),
      $view->description,
      implode(', ', $provides),
      $url,
      $status,
      theme('links', $links),
    );
  }
  if ($items) {
    $output .= theme('table', array(
      t('Default view'),
      t('Title'),
      t('Description'),
      t('Provides'),
      t('URL'),
      t('Status'),
      t('Actions'),
    ), $items, array(
      "cellpadding" => "4",
    ), t('Default Views'));
  }
  else {
    $output .= t('<p>No views have currently been defined.</p>');
  }
  return $output;
}
function views_ui_admin_tools() {
  $form['markup'] = array(
    '#value' => t('<p>Occasionally, something or other can cause the Views cache to contain stale data; this is particularly true after module updates and sometimes true after taxonomy and profile updates. If you are having problems with Views creating malformed queries, the first thing you should always do is clear the Views cache to see if that is the problem.</p>'),
  );
  $form['clear'] = array(
    '#type' => 'submit',
    '#value' => t('Clear views cache'),
  );
  return $form;
}
function views_ui_admin_tools_submit($form_id, $form) {
  if ($_POST['op'] == t('Clear views cache')) {
    views_invalidate_cache();
    drupal_set_message("The Views cache has been cleared.");
  }
}

/*
 * Page to enable a disabled default view
 */
function views_ui_admin_enable_page($view = '') {
  if (isset($_GET['token']) && drupal_valid_token($_GET['token'], 'views-enable')) {
    views_load_cache();
    if ($view) {
      $views_status = variable_get('views_defaults', array());
      $views_status[$view] = 'enabled';
      variable_set('views_defaults', $views_status);
      menu_rebuild();
    }
    drupal_goto('admin/build/views');
  }
  else {
    return drupal_access_denied();
  }
}

/*
 * Page to disable an enabled default view
 */
function views_ui_admin_disable_page($view = '') {
  if (isset($_GET['token']) && drupal_valid_token($_GET['token'], 'views-disable')) {
    views_load_cache();
    if ($view) {
      $views_status = variable_get('views_defaults', array());
      $views_status[$view] = 'disabled';
      variable_set('views_defaults', $views_status);
      menu_rebuild();
    }
    drupal_goto('admin/build/views');
  }
  else {
    return drupal_access_denied();
  }
}

/*
 * Provide a textarea to paste a view export into.
 */
function views_ui_admin_import_page() {
  views_load_cache();
  if ($_POST['form_id'] == 'views_edit_view') {
    return views_ui_admin_add_page();
  }
  drupal_set_title(t('Import a View'));
  return drupal_get_form('views_ui_admin_import', $form);
}
function views_ui_admin_import() {
  $form['view'] = array(
    '#type' => 'textarea',
    '#title' => t('Import View Code'),
    '#cols' => 60,
    '#rows' => 6,
    '#description' => t('Cut and paste the results of an Export View here.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t("Submit"),
  );
  $form['#redirect'] = NULL;
  return $form;
}

/*
 * Handle the submit button on importing a view.
 */
function views_ui_admin_import_submit($formid, $form) {
  views_load_cache();
  ob_start();
  eval($form['view']);
  ob_end_clean();
  $tables = array_keys(_views_get_tables());
  if (isset($view)) {
    if (!is_array($view->requires) || !array_diff($view->requires, $tables)) {
      views_sanitize_view($view);
      drupal_set_title(t('Add a View'));
      $output = drupal_get_form('views_edit_view', $view, NULL);
      print theme('page', $output);
      exit;
    }
    else {
      drupal_set_message(t("You don't seem to have the following requirements: ") . implode(', ', array_diff($view->requires, $tables)));
    }
  }
  else {
    drupal_set_message(t('Unable to get a view out of that.'));
  }
}

/*
 * Export a view for cut & paste.
 */
function views_ui_admin_export_page($vid = '') {
  views_load_cache();
  $code = views_create_view_code($vid);
  $lines = substr_count($code, "\n");
  $form['code'] = array(
    '#type' => 'textarea',
    '#title' => $view->name,
    '#default_value' => $code,
    '#rows' => $lines,
  );
  return $form;
}

/*
 * Provide a form to add a view. Allow adding a view from default templates.
 */
function views_ui_admin_add_page($template = NULL) {
  views_load_cache();
  $op = $_POST['op'];
  if ($op == t('Cancel')) {
    drupal_goto('admin/build/views');
  }
  $view = _views_get_default_view($template);
  drupal_set_title(t('Add a View'));
  return drupal_get_form('views_edit_view', $view, $op);
}

/*
 * Provide a form to clone a view.
 */
function views_ui_admin_clone_page($viewname) {
  views_load_cache();
  $op = $_POST['op'];
  if ($op == t('Cancel')) {
    drupal_goto('admin/build/views');
  }
  $view = views_get_view($viewname);
  if (!$view) {
    return drupal_not_found();
  }
  unset($view->vid);
  drupal_set_title(t('Add a View'));
  return drupal_get_form('views_edit_view', $view, $op);
}

/*
 * Provide a form to edit a view.
 */
function views_ui_admin_edit_page($vid = '') {
  views_load_cache();
  $op = $_POST['op'];
  if ($op == t('Cancel')) {
    drupal_goto('admin/build/views');
  }
  if ($op == t('Delete')) {
    drupal_goto("admin/build/views/delete/{$vid}");
  }
  if (!($view = _views_load_view($vid))) {
    drupal_goto('admin/build/views');
  }
  drupal_set_title(t('Edit view %n', array(
    '%n' => $view->name,
  )));
  return drupal_get_form('views_edit_view', $view, $op);
}

/*
 * Provide a form to confirm deletion of a view.
 */
function views_ui_admin_delete_confirm($vid = '') {
  $view = _views_load_view($vid);
  if (!$view) {
    return drupal_goto('admin/build/views');
  }
  $form['vid'] = array(
    '#type' => 'value',
    '#value' => $view->vid,
  );

  // bdragon note: Did you mean to drop the above line on the floor with this?
  $form = confirm_form($form, t('Are you sure you want to delete %title?', array(
    '%title' => $view->name,
  )), $_GET['destination'] ? $_GET['destination'] : 'admin/build/views', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
  return $form;
}

/*
 * Handle the submit button to delete a view.
 */
function views_ui_admin_delete_confirm_submit($form_id, $form) {
  _views_delete_view((object) $form);
  menu_rebuild();
}

/*
 * Get an empty view with basic defaults.
 */
function _views_get_default_view($template = '') {
  if ($template) {
    $default_views = _views_get_default_views();
    if (isset($default_views[$template])) {
      $view = $default_views[$template];
    }
  }
  if (!$view) {
    $view = new stdClass();
    $view->use_pager = true;
    $view->nodes_per_page = variable_get('default_nodes_main', 10);
    $view->page_header_format = variable_get('filter_default_format', 1);
    $view->page_footer_format = variable_get('filter_default_format', 1);
    $view->page_header_format = variable_get('filter_default_format', 1);
    $view->block_header_format = variable_get('filter_default_format', 1);
    $view->block_footer_format = variable_get('filter_default_format', 1);
    $view->block_header_format = variable_get('filter_default_format', 1);
    $view->vid = 0;
  }
  return _views_check_arrays($view);
}

// ---------------------------------------------------------------------------
// Select Box Definitions
// These should probably have string array keys that are easier to identify.

/**
 * Select box entries for argument defaults.
 */
function _views_get_arguments_default() {
  return array(
    1 => t('Return Page Not Found'),
    2 => t('Display All Values'),
    3 => t('Summary, unsorted'),
    4 => t('Summary, sorted ascending'),
    5 => t('Summary, sorted descending'),
    6 => t('Summary, sorted as view'),
    7 => t('Use Empty Text'),
  );
}

/**
 * Select box entries for sort ordering.
 */
function _views_sortorders() {
  return array(
    'ASC' => t('Ascending'),
    'DESC' => t('Descending'),
  );
}

/**
 * Swap two items in an array.
 */
function _views_swap(&$arr, $a, $b) {
  $temp = $arr[$a];
  $arr[$a] = $arr[$b];
  $arr[$b] = $temp;
}

/**
 * Move an item up in an array.
 */
function _views_move_up(&$arr, $i) {
  if ($i <= 0 || $i >= count($arr)) {
    return;

    // can't do it.
  }
  _views_swap($arr, $i - 1, $i);
}

/**
 * Move an item down in an array.
 */
function _views_move_down(&$arr, $i) {
  if ($i >= count($arr) - 1 || $i < 0) {
    return;

    // can't do it.
  }
  _views_swap($arr, $i + 1, $i);
}

/**
 * Move an item to the front of an array.
 */
function _views_move_top(&$arr, $i) {
  if ($i <= 0 || $i >= count($arr)) {
    return;

    // can't do it.
  }
  $temp = $arr[$i];
  for ($x = $i; $x > 0; $x--) {
    $arr[$x] = $arr[$x - 1];
  }
  $arr[0] = $temp;
}

/**
 * Move an item to the end of an array.
 */
function _views_move_bottom(&$arr, $i) {
  $end = count($arr) - 1;
  if ($i >= $end || $i < 0) {
    return;

    // can't do it.
  }
  $temp = $arr[$i];
  for ($x = $i; $x < $end; $x++) {
    $arr[$x] = $arr[$x + 1];
  }
  $arr[$end] = $temp;
}

/**
 * Figure out which of the many, many buttons on a form were clicked and
 * handle it.
 */
function _views_check_sub_ops(&$form, &$order, $i) {
  if ($form['delete']['#value']) {
    unset($form['delete']['#value']);
    unset($order[$i]);
    $order = array_values($order);

    // reindex
    $form['delete']['#printed'] = true;
    $form['up']['#printed'] = true;
    $form['down']['#printed'] = true;
    $form['top']['#printed'] = true;
    $form['bottom']['#printed'] = true;
    return 'delete';
  }
  else {
    foreach (array(
      'up',
      'down',
      'top',
      'bottom',
    ) as $dir) {
      if ($form[$dir]['#value']) {
        unset($form[$dir]['#value']);
        $func = "_views_move_{$dir}";
        $func($order, $i);
        return true;
      }
    }
  }
  return false;
}

/**
 * Figure out if one of the add buttons on a form were clicked, and handle it.
 */
function _views_check_ops(&$view, $op, $form) {
  if ($op == t('Add Filter')) {
    $view->new_filter['id'] = $form['filter']['add']['id']['#value'];
    return 'filter';
  }
  else {
    if ($op == t('Add Criteria')) {
      $view->new_sort['id'] = $form['sort']['add']['id']['#value'];
      return 'sort';
    }
    else {
      if ($op == t('Add Argument')) {
        $view->new_argument['id'] = $form['argument']['add']['id']['#value'];
        return 'argument';
      }
      else {
        if ($op == t('Add Field')) {
          $fieldbits = explode('.', $form['field']['add']['id']['#value']);
          $view->new_field['id'] = $form['field']['add']['id']['#value'];
          $view->new_field['tablename'] = $fieldbits[0];
          $view->new_field['field'] = $fieldbits[1];
          $view->new_field['queryname'] = "{$fieldbits[0]}_{$fieldbits[1]}";
          return 'field';
        }
        else {
          if ($op == t('Expose Filter')) {
            $view->new_exposed_filter['id'] = $form['exposed_filter']['add']['id']['#value'];
            return 'filter';
          }
        }
      }
    }
  }
}

/**
 * Custom form element to do our nice images.
 */
function views_elements() {
  $type['views_imagebutton'] = array(
    '#input' => TRUE,
    '#button_type' => 'submit',
  );
  return $type;
}
function theme_views_imagebutton($element) {
  return '<input type="image" class="form-' . $element['#button_type'] . '" name="' . $element['#name'] . '" value="' . check_plain($element['#default_value']) . '" ' . drupal_attributes($element['#attributes']) . ' src="' . $element['#image'] . '" alt="' . $element['#title'] . '" title="' . $element['#title'] . "\" />\n";
}
function views_imagebutton_value() {

  // null function guarantees default_value doesn't get moved to #value.
}

/**
 * Set up the dynamic #options on a widget
 */
function views_ui_setup_widget($widget, $default_value, $argument = NULL) {
  if (!$argument) {
    $argument = $widget;
  }
  if (is_string($widget['#options']) && function_exists($widget['#options'])) {
    $widget['#options'] = $widget['#options']('option', $argument);
  }
  if ($widget['#multiple'] && is_array($widget['#options'])) {
    $widget['#size'] = min(count($widget['#options']), 8);
  }
  $widget['#default_value'] = $default_value;
  return $widget;
}

/**
 * Display all the guts of a view in a form for editing.
 */
function views_edit_view($view, $op = '') {
  _views_check_arrays($view);

  // make sure arrays that might be empty get set
  // Put in all our add buttons, then process them to see if they've been hit.
  $form = array();
  views_ui_add_add_button($form, 'field', _views_get_fields(true), t('Add Field'));
  views_ui_add_add_button($form, 'argument', _views_get_arguments(true), t('Add Argument'));
  views_ui_add_add_button($form, 'filter', _views_get_filters(true), t('Add Filter'));
  views_ui_add_add_button($form, 'sort', _views_get_sorts(true), t('Add Criteria'));
  $allbut = _views_check_ops($view, $op, $form);
  if ($_POST['edit'] && $op != t('Save')) {
    drupal_set_message(t('You have modified this view; changes will not be recorded until you Save the form.'));
  }
  $form['exposed_filter'] = array();
  foreach (array(
    'field',
    'argument',
    'filter',
    'exposed_filter',
    'sort',
  ) as $section) {
    if (views_ui_add_section($form[$section], $view, $section)) {
      $allbut = $section;
    }
  }
  $form['vid'] = array(
    '#type' => 'value',
    '#value' => $view->vid,
  );
  $form['allbut'] = array(
    '#type' => 'value',
    '#value' => $allbut,
  );
  $form['changed'] = array(
    '#type' => 'hidden',
    '#value' => $view->changed,
  );
  $form['basic-info'] = array(
    '#type' => 'fieldset',
    '#collapsible' => true,
    '#collapsed' => $allbut != NULL,
    '#title' => t('Basic Information'),
  );
  $form['basic-info']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $view->name,
    '#size' => 20,
    '#maxlength' => 32,
    '#description' => t('The unique identifier of the view; it is only important for overridden views and views that modules or themes will need to use. Only alphanumeric and _ allowed here'),
    '#required' => true,
  );
  $form['basic-info']['access'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Access'),
    '#default_value' => $view->access,
    '#options' => views_handler_filter_role(),
    '#description' => t('Only the checked roles will be able to see this view in any form; if no roles are checked, access will not be restricted.'),
  );
  $form['basic-info']['description'] = array(
    '#type' => 'textfield',
    '#title' => t('Description'),
    '#default_value' => $view->description,
    '#size' => 60,
    '#maxlength' => 255,
    '#description' => t('A description of the view for the admin list.'),
  );

  // page info
  $form['page-info'] = array(
    '#type' => 'fieldset',
    '#collapsible' => true,
    '#collapsed' => $allbut != NULL || !$view->page,
    '#title' => t('Page'),
  );
  $form['page-info']['page'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide Page View'),
    '#return_value' => 1,
    '#default_value' => $view->page,
    '#description' => t('If checked this view will be provided as a page. If not checked, the fields in this group will be ignored.'),
  );
  $form['page-info']['url'] = array(
    '#type' => 'textfield',
    '#title' => t('URL'),
    '#default_value' => $view->url,
    '#size' => 60,
    '#maxlength' => 255,
    '#description' => t('Enter the URL to use for this view in the form of \'dir/dir\'. Do not begin or end the URL with a /. Example: \'view/tracker\'. This is required if providing a page view. You can also add $arg as a placeholder for arguments passed in the URL, for example \'user/$arg/tracker\' or \'node/$arg/related\'. Note that any arguments listed here will be required, even if they are listed as optional below. You do not need to list arguments at the end of the path. Do not try to use URLs such as taxonomy/term/$arg.'),
  );
  $form['page-info']['page_type'] = array(
    '#type' => 'select',
    '#title' => t('View Type'),
    '#default_value' => $view->page_type,
    '#options' => _views_get_style_plugins(true),
    '#description' => t('How the nodes should be displayed to the user.'),
  );
  $form['page-info']['page_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $view->page_title,
    '#size' => 60,
    '#maxlength' => 255,
    '#description' => t('The title that be shown at the top of the view. May be blank. This title ignores arguments; if you want your title to take arguments into account, use the "title" field in the arguments section.'),
  );
  $form['page-info']['use_pager'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use Pager'),
    '#return_value' => 1,
    '#default_value' => $view->use_pager,
    '#description' => t('If checked this query may be multiple pages. If not checked this query will be one page.'),
  );
  $form['page-info']['breadcrumb_no_home'] = array(
    '#type' => 'checkbox',
    '#title' => t('Breadcrumb trail should not include "Home"'),
    '#return_value' => 1,
    '#default_value' => $view->breadcrumb_no_home,
    '#description' => t('If checked the breadcrumb trail for this page will discard "Home". Usually you will not set this, but this is used for the Front Page View, where it IS Home and should not leave a trail to itself.'),
  );
  $form['page-info']['nodes_per_page'] = array(
    '#type' => 'textfield',
    '#title' => t('Nodes per Page'),
    '#default_value' => intval($view->nodes_per_page),
    '#size' => 5,
    '#maxlength' => 5,
    '#description' => t('The number of nodes to display per page. If 0, all nodes will be displayed. If not using a pager, this will be the maximum number of nodes in the list.'),
    '#attributes' => NULL,
  );
  $form['page-info']['page_header_fieldset'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Header'),
  );
  $form['page-info']['page_header_fieldset']['page_header'] = array(
    '#type' => 'textarea',
    '#default_value' => $view->page_header,
    '#cols' => 60,
    '#rows' => 6,
    '#description' => t('Text to display at the top of the view. May contain an explanation or links or whatever you like. Optional.'),
  );
  $form['page-info']['page_header_fieldset']['format'] = filter_form($view->page_header_format, 1, array(
    'page_header_format',
  ));
  $form['page-info']['page_footer_fieldset'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Footer'),
  );
  $form['page-info']['page_footer_fieldset']['page_footer'] = array(
    '#type' => 'textarea',
    '#default_value' => $view->page_footer,
    '#cols' => 60,
    '#rows' => 6,
    '#description' => t('Text to display at the bottom of the view. May contain an explanation or links or whatever you like. Optional.'),
  );
  $form['page-info']['page_footer_fieldset']['format'] = filter_form($view->page_footer_format, 1, array(
    'page_footer_format',
  ));
  $form['page-info']['page_empty_fieldset'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Empty Text'),
  );
  $form['page-info']['page_empty_fieldset']['page_empty'] = array(
    '#type' => 'textarea',
    '#default_value' => $view->page_empty,
    '#cols' => 60,
    '#rows' => 6,
    '#description' => t('Text to display if a view returns no nodes. Optional.'),
  );
  $form['page-info']['page_empty_fieldset']['format'] = filter_form($view->page_empty_format, 1, array(
    'page_empty_format',
  ));
  $form['page-info']['menu-info'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Menu'),
  );
  $form['page-info']['menu-info']['menu'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide Menu'),
    '#return_value' => 1,
    '#default_value' => $view->menu,
    '#description' => t('If checked this view be given a menu entry in the Drupal menu system. If not checked the data in this group will be ignored.'),
  );
  $form['page-info']['menu-info']['menu_tab'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide Menu as Tab'),
    '#return_value' => 1,
    '#default_value' => $view->menu_tab,
    '#description' => t("If checked this view's menu entry will be provided as a tab rather than in the main menu system."),
  );
  $form['page-info']['menu-info']['menu_tab_weight'] = array(
    '#type' => 'textfield',
    '#title' => t('Tab Weight'),
    '#default_value' => $view->menu_tab_weight,
    '#width' => 10,
    '#description' => t('If this is a menu tab, select the weight; lower numbers will be further to the left.'),
  );
  $form['page-info']['menu-info']['menu_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Menu Title'),
    '#default_value' => $view->menu_title,
    '#size' => 60,
    '#maxlength' => 255,
    '#description' => t('Enter the title to use for the menu entry or tab. If blank, the page title will be used.'),
  );
  $form['page-info']['menu-info']['default-tab'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Default Menu Tab'),
  );
  $form['page-info']['menu-info']['default-tab']['menu_tab_default'] = array(
    '#type' => 'checkbox',
    '#title' => t('Make Default Menu Tab'),
    '#return_value' => 1,
    '#default_value' => $view->menu_tab_default,
    '#description' => t("If checked this view's menu entry will be provided as a tab, and will be the default tab for that URL path. For example, if the URL is 'tracker/all' and it is set as the default menu tab, it will be put into the menu as 'tracker' and 'tracker/all' will be the default tab. The following settings allow you to customize the parent item, for example 'tracker'. For tabs to work properly, one tab in the group must be set as the default."),
  );
  $form['page-info']['menu-info']['default-tab']['menu_tab_default_parent_type'] = array(
    '#type' => 'select',
    '#title' => t('Parent Menu Item Type'),
    '#default_value' => $view->menu_tab_default_parent_type,
    '#options' => array(
      'tab' => t("Tab"),
      'normal' => t("Normal menu item"),
      'existing' => t("Already exists (don't create)"),
    ),
    '#description' => t("Select type of parent item to use for this default menu tab. You can either specify the parent should be a tab (the default), a normal menu item, or to use the menu item that already exists at the specified URL. For example, if the URL for the default tab is 'tracker/all', then 'tracker' would already have to be a valid menu item to use this final choice."),
  );
  $form['page-info']['menu-info']['default-tab']['menu_parent_tab_weight'] = array(
    '#type' => 'textfield',
    '#title' => t('Tab Weight'),
    '#default_value' => $view->menu_parent_tab_weight,
    '#width' => 10,
    '#description' => t('If the parent menu item is a tab, select the weight; lower numbers will be further to the left.'),
  );
  $form['page-info']['menu-info']['default-tab']['menu_parent_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Parent Menu Item Title'),
    '#default_value' => $view->menu_parent_title,
    '#size' => 60,
    '#maxlength' => 255,
    '#description' => t('If the Parent Menu Item is being defined by this view (if you set the %type_field to either %tab or %menu), you can specify its title here.  If blank, the menu title will be used if that is defined, or the page title if not.', array(
      '%type_field' => t('Parent Menu Item Type'),
      '%tab' => t('Tab'),
      '%menu' => t('Normal menu item'),
    )),
  );

  // block info
  $form['block-info'] = array(
    '#type' => 'fieldset',
    '#collapsible' => true,
    '#collapsed' => $allbut != NULL || !$view->block,
    '#title' => t('Block'),
  );
  $form['block-info']['block'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide Block'),
    '#return_value' => 1,
    '#default_value' => $view->block,
    '#description' => t('If checked this view will be provided as a block. If checked title may not be blank.'),
  );
  $form['block-info']['block_type'] = array(
    '#type' => 'select',
    '#title' => t('View Type'),
    '#default_value' => $view->block_type,
    '#options' => _views_get_style_plugins(true),
    '#description' => t('How the nodes should be displayed to the user.'),
  );
  $form['block-info']['block_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $view->block_title,
    '#size' => 60,
    '#maxlength' => 255,
    '#description' => t('The title that will be shown at the top of the block. May be blank.'),
  );
  $form['block-info']['nodes_per_block'] = array(
    '#type' => 'textfield',
    '#title' => t('Nodes per Block'),
    '#default_value' => $view->nodes_per_block,
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t('If using a block, the maximum number of items to display in the block. Pagers are not used in blocks.'),
    '#attributes' => NULL,
  );
  $form['block-info']['block_more'] = array(
    '#type' => 'checkbox',
    '#title' => t('[More] Link?'),
    '#return_value' => 1,
    '#default_value' => $view->block_more,
    '#description' => t('If using a view as both a page and a block, display a more link in the block that links to the view URL?'),
  );
  $form['block-info']['block_header_fieldset'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Header'),
  );
  $form['block-info']['block_header_fieldset']['block_use_page_header'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use Page Header'),
    '#return_value' => 1,
    '#default_value' => $view->block_use_page_header,
    '#description' => t('If checked, use the Page Header for block view instead. If so, you should leave the Block Header blank.'),
  );
  $form['block-info']['block_header_fieldset']['block_header'] = array(
    '#type' => 'textarea',
    '#title' => t('Header'),
    '#default_value' => $view->block_header,
    '#cols' => 60,
    '#rows' => 6,
    '#description' => t('Text to display at the top of the view. May contain an explanation or links or whatever you like. Optional.'),
  );
  $form['block-info']['block_header_fieldset']['format'] = filter_form($view->block_header_format, 1, array(
    'block_header_format',
  ));
  $form['block-info']['block_footer_fieldset'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Footer'),
  );
  $form['block-info']['block_footer_fieldset']['block_use_page_footer'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use Page Footer'),
    '#return_value' => 1,
    '#default_value' => $view->block_use_page_footer,
    '#description' => t('If checked, use the page footer for block view instead. If so, you should leave the block footer blank.'),
  );
  $form['block-info']['block_footer_fieldset']['block_footer'] = array(
    '#type' => 'textarea',
    '#title' => t('Footer'),
    '#default_value' => $view->block_footer,
    '#cols' => 60,
    '#rows' => 6,
    '#description' => t('Text to display at the bottom of the view. May contain an explanation or links or whatever you like. Optional.'),
  );
  $form['block-info']['block_footer_fieldset']['format'] = filter_form($view->block_footer_format, 1, array(
    'block_footer_format',
  ));
  $form['block-info']['block_empty_fieldset'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Empty text'),
  );
  $form['block-info']['block_empty_fieldset']['block_use_page_empty'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use Page empty'),
    '#return_value' => 1,
    '#default_value' => $view->block_use_page_empty,
    '#description' => t('If checked, use the Page Empty Text for block view instead. If so, you should leave the block empty text blank.'),
  );
  $form['block-info']['block_empty_fieldset']['block_empty'] = array(
    '#type' => 'textarea',
    '#title' => t('Empty text'),
    '#default_value' => $view->block_empty,
    '#cols' => 60,
    '#rows' => 6,
    '#description' => t('Text to display if a view results in no nodes. Optional.'),
  );
  $form['block-info']['block_empty_fieldset']['format'] = filter_form($view->block_empty_format, 1, array(
    'block_empty_format',
  ));
  $access = user_access('use PHP for block visibility');
  if ($access) {
    $form['view_args_php_fieldset'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => empty($view->view_args_php) ? TRUE : FALSE,
      '#title' => t('Argument Handling Code'),
    );
    $form['view_args_php_fieldset']['view_args_php'] = array(
      '#type' => 'textarea',
      '#title' => t('Argument Code'),
      '#default_value' => $view->view_args_php,
      '#cols' => 60,
      '#rows' => 6,
      '#description' => '<p>' . t('Advanced Usage Only: PHP code that returns a custom array of arguments for the view. Should not include &lt;?php ?&gt; delimiters.') . '</p>' . '<p>' . t('For more information, please see the <a href="!arg">Argument Handling Code documentation</a> in the Drupal handbook.', array(
        '!arg' => 'http://drupal.org/node/70145',
      )) . '</p>',
    );
  }
  else {
    $form['view_args_php_fieldset']['view_args_php'] = array(
      '#type' => 'value',
      '#value' => $view->view_args_php,
    );
  }
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['save_and_edit'] = array(
    '#type' => 'submit',
    '#value' => t('Save and edit'),
  );
  if ($view->vid) {
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }
  $form['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );

  // Add the css file for form display.
  drupal_add_css(drupal_get_path('module', 'views_ui') . '/views_ui.css');
  return $form;
}

/**
 * separately build a piece of the form
 */
function views_ui_build_form(&$form) {

  // NOT REALLY SURE WHY THIS SORT OF WORKS. IT'S MAGIC THAT CHX POINTED ME TO
  // IN THE POLL MODULE.
  $form['#post'] = $_POST;
  $form = form_builder('views_edit_view', $form);
}

/**
 * Add the 'add' button for a section into the form
 */
function views_ui_add_add_button(&$form, $section, $options, $label) {
  $form[$section]['add'] = array(
    '#tree' => true,
    '#parents' => array(
      $section,
      'add',
    ),
  );
  $form[$section]['add']['id'] = array(
    '#type' => 'select',
    '#options' => $options,
  );
  $form[$section]['add']['button'] = array(
    '#type' => 'button',
    '#value' => $label,
  );
  views_ui_build_form($form[$section]['add']);
}

/**
 * Add one of the list sections to the form.
 */
function views_ui_add_section(&$form, &$view, $section) {

  // add fields to the form.
  $form += array(
    '#tree' => true,
    '#parents' => array(
      $section,
    ),
  );
  $view_section =& $view->{$section};
  $num_items = count($view_section);

  // Populate the form with fields we need to check to track
  // changes through the form's life.
  $form['count'] = array(
    '#type' => 'hidden',
    '#default_value' => $num_items,
  );
  $form['order'] = array(
    '#type' => 'hidden',
    '#default_value' => $num_items ? implode(',', range(0, $num_items - 1)) : '',
  );

  // Run the builder to get the value on the form.
  views_ui_build_form($form);
  $order = $form['order']['#value'] != '' ? explode(',', $form['order']['#value']) : array();

  // Shortcut because operator precedence gets sticky if using $foo->$bar[]
  for ($i = $num_items; $i < $form['count']['#value']; $i++) {
    $view_section[] = array();
  }
  $new_section = "new_{$section}";

  // instantiate the new field if one was added.
  if ($view->{$new_section}) {
    $view_section[] = $view->{$new_section};
    $order[] = $form['count']['#value'];
    $form['count']['#value']++;
  }
  $func = "views_ui_add_{$section}";
  if ($order) {
    foreach ($order as $key => $i) {
      $form[$i] = array(
        '#tree' => true,
        '#parents' => array(
          $section,
          $i,
        ),
      );
      $form[$i]['id'] = array(
        '#type' => 'hidden',
        '#default_value' => $view_section[$i]['id'],
      );
      views_ui_add_buttons($form[$i]);
      views_ui_build_form($form[$i]);
      $retval = _views_check_sub_ops($form[$i], $order, $key);
      if ($retval !== 'delete') {
        $retval2 = $func($form[$i], $view_section[$i], $order, $key, $i, $view);
      }
      if ($retval || $retval2) {
        $allbut = $section;
      }
    }
    $form['order']['#value'] = implode(',', $order);
  }
  return $allbut;
}

/**
 * Add all the info for a single field into the form.
 */
function views_ui_add_field(&$form, $field, &$order, $key, $i) {
  $fields = _views_get_fields();
  $fieldname = $form['id']['#value'];

  // combined table & fieldname
  $fieldinfo = $fields[$fieldname];

  // laziness + readability
  $form['fullname'] = array(
    '#type' => 'hidden',
    '#default_value' => $field['id'],
  );
  $form['name'] = array(
    '#type' => 'markup',
    '#value' => $fieldinfo['name'],
  );
  $form['queryname'] = array(
    '#type' => 'hidden',
    '#default_value' => $field['queryname'],
  );
  $form['tablename'] = array(
    '#type' => 'hidden',
    '#default_value' => $field['tablename'],
  );
  $form['field'] = array(
    '#type' => 'hidden',
    '#default_value' => $field['field'],
  );
  $form['label'] = array(
    '#type' => 'textfield',
    '#default_value' => $field['label'],
    '#size' => 15,
    '#maxlength' => 255,
  );
  if (is_array($fieldinfo['handler'])) {
    $form['handler'] = array(
      '#type' => 'select',
      '#default_value' => $field['handler'],
      '#options' => $fieldinfo['handler'],
    );
  }
  if (isset($fieldinfo['option'])) {
    $form['options'] = views_ui_setup_widget($fieldinfo['option'], $field['options']);
  }
  if ($fieldinfo['sortable']) {
    $form['sortable'] = array(
      '#type' => 'select',
      '#default_value' => $field['sortable'],
      '#options' => array(
        '0' => t('No'),
        '1' => t('Yes'),
      ),
    );
    $form['defaultsort'] = array(
      '#type' => 'select',
      '#default_value' => $field['defaultsort'],
      '#options' => array(
        '0' => t('None'),
        'ASC' => t('Ascending'),
        'DESC' => t('Descending'),
      ),
    );
  }
  if (isset($fieldinfo['help'])) {
    $form['help'] = array(
      '#type' => 'markup',
      '#value' => '<div class="description">' . $fieldinfo['help'] . '</div>',
    );
  }
}

/**
 * Add all the info for a single argument into the form.
 */
function views_ui_add_argument(&$form, $argument, &$order, $key, $i) {
  $arguments = _views_get_arguments();
  $arg_type = $form['id']['#value'];
  $arginfo = $arguments[$arg_type];
  $form['type'] = array(
    '#type' => 'hidden',
    '#default_value' => $argument['id'],
  );
  $form['name'] = array(
    '#value' => $arginfo['name'],
  );
  $form['argdefault'] = array(
    '#type' => 'select',
    '#default_value' => max(1, intval($argument['argdefault'])),
    '#options' => _views_get_arguments_default(),
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#default_value' => $argument['title'],
    '#size' => 10,
    '#maxlength' => 255,
  );
  if (isset($arginfo['option'])) {
    $form['options'] = views_ui_setup_widget($arginfo['option'], $argument['options']);
  }
  $form['wildcard'] = array(
    '#type' => 'textfield',
    '#default_value' => $argument['wildcard'],
    '#size' => 5,
    '#maxlength' => 32,
  );
  $form['wildcard_substitution'] = array(
    '#type' => 'textfield',
    '#default_value' => $argument['wildcard_substitution'],
    '#size' => 5,
    '#maxlength' => 32,
  );
  if (isset($arginfo['help'])) {
    $form['help'] = array(
      '#type' => 'markup',
      '#value' => $arginfo['help'],
    );
  }
}

/**
 * Add all the info for a single filter into the form.
 */
function views_ui_add_filter(&$form, $filter, &$order, $key, $i, &$view) {
  $filters = _views_get_filters();
  $filtername = $form['id']['#value'];

  // combined table & filtername
  $filterinfo = $filters[$filtername];
  $form['field'] = array(
    '#type' => 'hidden',
    '#default_value' => $filter['id'],
  );
  $form['name'] = array(
    '#type' => 'markup',
    '#value' => $filterinfo['name'],
  );

  // 'operator' is either an array or a handler
  $operator = $filterinfo['operator'];
  if (!is_array($operator) && function_exists($filterinfo['operator'])) {
    $operator = $filterinfo['operator']('operator', $filterinfo);
  }
  $form['operator'] = array(
    '#type' => 'select',
    '#default_value' => $filter['operator'],
    '#options' => $operator,
  );
  if (isset($filterinfo['option'])) {
    $form['options'] = views_ui_setup_widget($filterinfo['option'], $filter['options']);
  }
  $form['value'] = views_ui_setup_widget($filterinfo['value'], $filter['value'], $filterinfo);
  if (isset($filterinfo['help'])) {
    $form['help'] = array(
      '#type' => 'markup',
      '#value' => $filterinfo['help'],
    );
  }

  // This is kind of a pain in the butt -- The only way to know all of
  // the filters that have been exposed is to look at the form, but that
  // part of the form hasn't been built yet, so I can't use the form_builder
  // method. I can't put this after that, either, because then I'd have to
  // go back to add one if we see one here. So we cheat heavily with _POST.
  if ($_POST['edit']) {
    $exposed_order = $_POST['edit']['exposed_filter']['order'];
    if ($exposed_order !== '') {
      $exposed_order = explode(',', $exposed_order);
      foreach ($exposed_order as $x) {
        if ($_POST['edit']['exposed_filter'][$x]['id'] == $filtername) {
          $exposed = true;
          break;
        }
      }
    }
  }
  else {

    // do this if there's never been a submit.
    $exposed_order = array_keys($view->exposed_filter);
    foreach ($exposed_order as $x) {
      if ($view->exposed_filter[$x]['id'] == $filtername) {
        $exposed = true;
        break;
      }
    }
  }
  if (!$exposed) {

    // I can't find a way to see if this button was pressed other than
    // directly checking, because #form_submitted doesn't work on arrays
    if ($_POST['edit']['filter'][$i]['expose']) {
      $view->new_exposed_filter['id'] = $filtername;
      return true;
    }
    else {
      $form['expose'] = array(
        '#type' => 'button',
        '#default_value' => t('Expose'),
        '#name' => "edit[filter][{$i}][expose]",
      );
    }
  }
}

/**
 * Add all the info for a single exposed filter into the form.
 */
function views_ui_add_exposed_filter(&$form, $filter, &$order, $key, $i) {
  $filters = _views_get_filters();
  $filtername = $form['id']['#value'];

  // combined table & filtername
  $filterinfo = $filters[$filtername];
  $form['field'] = array(
    '#type' => 'hidden',
    '#default_value' => $filter['id'],
  );
  $form['name'] = array(
    '#type' => 'markup',
    '#value' => $filterinfo['name'],
  );
  $form['label'] = array(
    '#type' => 'textfield',
    '#default_value' => $filter['label'],
    '#size' => 15,
    '#maxlength' => 255,
  );
  $form['optional'] = array(
    '#type' => 'checkbox',
    '#default_value' => $filter['optional'],
  );
  $form['is_default'] = array(
    '#type' => 'checkbox',
    '#default_value' => $filter['is_default'],
  );
  $form['single'] = array(
    '#type' => 'checkbox',
    '#default_value' => $filter['single'],
  );
  $form['operator'] = array(
    '#type' => 'checkbox',
    '#default_value' => $filter['operator'],
  );
}

/**
 * Add all the info for a single sort into the form.
 */
function views_ui_add_sort(&$form, $sort, &$order, $key, $i) {
  $sorts = _views_get_sorts();
  $sortname = $form['id']['#value'];

  // combined table & sortname
  $sortinfo = $sorts[$sortname];
  $form['field'] = array(
    '#type' => 'hidden',
    '#default_value' => $sort['id'],
  );
  $form['name'] = array(
    '#value' => $sortinfo['name'],
  );
  $form['sortorder'] = array(
    '#type' => 'select',
    '#title' => NULL,
    '#default_value' => $sort['sortorder'],
    '#options' => _views_sortorders(),
  );

  // option can be either 'string', 'integer', an array or a handler
  // that must return an array.
  if (isset($sortinfo['option'])) {
    $form['options'] = views_ui_setup_widget($sortinfo['option'], $sort['options']);
  }
  if (isset($sortinfo['help'])) {
    $form['help'] = array(
      '#type' => 'markup',
      '#value' => $sortinfo['help'],
    );
  }
}

/**
 * Add the up, down, top, bottom, delete buttons to a form.
 */
function views_ui_add_buttons(&$form_item) {
  $form_item['delete'] = views_ui_add_button('user-trash.png', t('Delete'), t('Delete this item.'));
  $form_item['up'] = views_ui_add_button('go-up.png', t('Up'), t('Move this item up.'));
  $form_item['down'] = views_ui_add_button('go-down.png', t('Down'), t('Move this item down.'));
  $form_item['top'] = views_ui_add_button('go-top.png', t('Top'), t('Move this item to the top.'));
  $form_item['bottom'] = views_ui_add_button('go-bottom.png', t('Bottom'), t('Move this item to the bottom.'));
}

/**
 * Add a single button to a form.
 */
function views_ui_add_button($image, $name, $text) {
  $module_path = base_path() . drupal_get_path('module', 'views');
  return array(
    '#type' => 'views_imagebutton',
    '#image' => $module_path . '/' . $image,
    '#title' => $text,
    '#default_value' => $name,
  );
}

/**
 * Display the form built by _views_view_form()
 */
function theme_views_edit_view($form) {
  $output .= drupal_render($form['basic-info'], false);
  $output .= drupal_render($form['page-info'], false);
  $output .= drupal_render($form['block-info'], false);
  $allbut = $form['allbut']['#value'];

  // drupal_render wants a reference so use full array notation.
  // fields
  $collapsed = $allbut && $allbut != 'field';
  $group = views_ui_render_section($form['field'], array(
    'name',
    'label',
    'handler',
    'options',
    'sortable',
    'defaultsort',
  ), array(
    t('Name'),
    t('Label'),
    t('Handler'),
    t('Option'),
    t('Sortable'),
    t('Default Sort'),
  ), 'fields', $collapsed);
  $group .= views_ui_render_section_add($form['field']['add'], array(
    'id',
    'button',
  ), t('Add Field'));
  $group .= '<p>' . t('Fields are only meaningful with List view and Table View; they allow you to choose which fields are presented and in what order.') . '</p>';
  $output .= theme('fieldset', array(
    '#title' => t('Fields'),
    '#children' => $group,
    '#collapsible' => true,
    '#collapsed' => $collapsed,
  ));

  // arguments
  $collapsed = $allbut && $allbut != 'argument';
  $group = views_ui_render_section($form['argument'], array(
    'name',
    'argdefault',
    'title',
    'options',
    'wildcard',
    'wildcard_substitution',
  ), array(
    t('Argument Type'),
    t('Default'),
    t('Title'),
    t('Option'),
    t('Wildcard'),
    t('Wildcard Sub'),
  ), 'arguments', $collapsed);
  $group .= views_ui_render_section_add($form['argument']['add'], array(
    'id',
    'button',
  ), t('Add Argument'));
  $group .= drupal_render($form['view_args_php_fieldset']);
  $group .= '<p>' . t('Arguments are parsed directly from the URL. They are not necessary to any given view, but allow flexibility.') . '</p>';
  $output .= theme('fieldset', array(
    '#title' => t('Arguments'),
    '#children' => $group,
    '#collapsible' => true,
    '#collapsed' => $collapsed,
  ));

  // filter
  $collapsed = $allbut && $allbut != 'filter';
  $group = views_ui_render_section($form['filter'], array(
    'name',
    'operator',
    'value',
    'options',
    'expose',
  ), array(
    t('Field'),
    t('Operator'),
    t('Value'),
    t('Option'),
    '',
  ), 'filters', $collapsed);
  $group .= views_ui_render_section_add($form['filter']['add'], array(
    'id',
    'button',
  ), t('Add Filter'));
  $group .= '<p>' . t('Filters allow you to select a subset of all the nodes to display. All Filters are ANDed together.') . '</p>';
  $output .= theme('fieldset', array(
    '#title' => t('Filters'),
    '#children' => $group,
    '#collapsible' => true,
    '#collapsed' => $collapsed,
  ));
  $group = '';

  // exposed exposed_filter
  $collapsed = $allbut && $allbut != 'exposed_filter';
  $group = views_ui_render_section($form['exposed_filter'], array(
    'name',
    'label',
    'optional',
    'is_default',
    'single',
    'operator',
  ), array(
    t('Field'),
    t('Label'),
    t('Optional'),
    t('Filter settings Default'),
    t('Force Single'),
    t('Lock Operator'),
  ), 'exposed_filters', $collapsed);

  //  $group .= views_ui_render_section_add($form['exposed_filter']['add'], array('id', 'button'), t('Expose Filter'));
  $group .= '<p>' . t('Exposed filters will be presented to the viewer. If not set required, then filters will include a "&lt;None&gt;" Value if possible. If set default, filters will default as set here, otherwise filter settings will be ignored. If Lock Operator is set, no operator will be made available to the user.') . '</p>';
  $output .= theme('fieldset', array(
    '#title' => t('Exposed Filters'),
    '#children' => $group,
    '#collapsible' => true,
    '#collapsed' => $collapsed,
  ));
  $group = '';

  // sort
  $collapsed = $allbut && $allbut != 'sort';
  $group = views_ui_render_section($form['sort'], array(
    'name',
    'sortorder',
    'options',
  ), array(
    t('Field'),
    t('Order'),
    t('Option'),
  ), 'sort criteria', $collapsed);
  $group .= views_ui_render_section_add($form['sort']['add'], array(
    'id',
    'button',
  ), t('Add criteria'));
  $output .= theme('fieldset', array(
    '#title' => t('Sort Criteria'),
    '#children' => $group,
    '#collapsible' => true,
    '#collapsed' => $collapsed,
  ));
  $output .= drupal_render($form, false);
  return $output;
}

/**
 * Render one of the dynamic sections on our form.
 */
function views_ui_render_section(&$form, $items, $header, $section, &$collapsed) {

  // always do the buttons
  $items = array_merge($items, array(
    'delete',
    'top',
    'up',
    'down',
    'bottom',
  ));
  $num_items = count($items);
  $order = $form['order']['#value'] != '' ? explode(',', $form['order']['#value']) : array();
  $count = count($order) - 1;
  foreach ($order as $key => $i) {
    $row = array();
    foreach ($items as $item) {

      // Hide the delete button on exposed filters.
      if ($item == 'delete' && $section == 'filters' && empty($form[$i]['expose'])) {
        $form[$i][$item]['#printed'] = true;
      }
      if ($key == 0 && ($item == 'up' || $item == 'top') || $key == $count && ($item == 'down' || $item == 'bottom')) {
        $form[$i][$item]['#printed'] = true;
        $row[] = '&nbsp;';

        // array('data' => '&nbsp;', 'width' => 16);
      }
      else {
        $row[] = drupal_render($form[$i][$item], false);
      }
    }
    $rows[] = $row;
    if (isset($form[$i]['help'])) {
      $rows[] = array(
        array(
          'data' => drupal_render($form[$i]['help']),
          'colspan' => $num_items,
        ),
      );
    }
  }
  if (!$rows) {
    $rows[] = array(
      array(
        'data' => t('This view currently has no %s defined.', array(
          '%s' => $section,
        )),
        'colspan' => $num_items,
      ),
    );
    $collapsed = true;
  }
  $header[] = array(
    'data' => t('Ops'),
    'colspan' => 5,
  );
  return theme('table', $header, $rows) . "<br />";
}

/**
 * Render the add buttons for one of the dynamic sections on our form.
 */
function views_ui_render_section_add(&$form, $items, $label) {
  asort($form['id']['#options']);
  foreach ($items as $item) {
    $row[] = drupal_render($form[$item], false);
  }
  $rows[] = $row;
  $header = array(
    array(
      'data' => $label,
      'colspan' => count($items),
    ),
  );
  return theme('table', $header, $rows) . "<br />";
}

/**
 * Validate that a view sent via form is OK.
 */
function views_edit_view_validate($form_id, $view, $form) {
  $op = $view['op'];
  if ($op != t('Save') && $op != t('Save and edit')) {
    return;

    // only validate on saving!
  }
  if ($view['vid']) {
    $changed = db_result(db_query("SELECT changed FROM {view_view} WHERE vid = %d", $view['vid']));
    if ($changed && $view['changed'] != $changed) {
      form_set_error('', t('Another user has modified this view, unable to save. You can get this error by using the Back button to re-edit a view after saving one; if you do this, be sure to Reload before making any changes!'));
      return;
    }
  }
  if (!$view['name']) {
    form_error($form['basic-info']['name'], t('View name is required.'));
  }

  // view name must be alphanumeric or underscores, no other punctuation.
  if (preg_match('/[^a-zA-Z0-9_]/', $view['name'])) {
    form_error($form['basic-info']['name'], t('View name must be alphanumeric or underscores only.'));
  }

  // test uniqueness of name
  $vid = db_result(db_query("SELECT vid FROM {view_view} WHERE name='%s'", $view['name']));
  if ($vid && $vid != $view['vid']) {
    form_error($form['basic-info']['name'], t('View name already in use.'));
  }
  if ($view['page']) {
    if ($view['use_pager'] && !$view['nodes_per_page']) {
      form_error($form['page-info']['nodes_per_page'], t('Nodes per page cannot be 0 if using the pager.'));
    }
  }
  if ($view['block'] && $view['nodes_per_block'] < 1) {
    form_error($form['block-info']['nodes_per_block'], t('If being used as a block, Nodes Per Block must be positive.'));
  }

  // validation based on type:
  $plugins = _views_get_style_plugins();
  if ($view['page']) {
    $validator = $plugins[$view['page_type']]['validate'];
    if (function_exists($validator)) {
      $validator('page', $view, $form);
    }
  }
  if ($view['block']) {
    $validator = $plugins[$view['block_type']]['validate'];
    if (function_exists($validator)) {
      $validator('block', $view, $form);
    }
  }
  foreach (array(
    'field',
    'argument',
    'sort',
    'filter',
  ) as $type) {
    $function = "_views_get_{$type}" . 's';
    $info = $function();
    if (is_array($view[$type])) {
      foreach ($view[$type] as $key => $data) {
        if (!is_numeric($key)) {
          continue;

          // some non-data data is in here.
        }
        $validator = $info[$data['id']]['validate'];
        if (function_exists($validator)) {
          $validator($data, $view, $form);
        }
      }
    }
  }
}
function views_ui_reorder(&$view) {

  // re-order things as they were ordered on the form.
  $order = $view['order'] != '' ? explode(',', $view['order']) : array();
  foreach ($order as $position => $key) {
    $placeholder[] = $view[$key];
  }
  $view = $placeholder;
}

/**
 * Handle submit buttons on a view form.
 */
function views_edit_view_submit($form_id, $form) {
  $view = (object) $form;

  // Transform any data that requires it here.
  $view->access = array_keys(array_filter($view->access));

  // ensure for MYSQL 5 irritation reasons.
  $view->nodes_per_page = intval($view->nodes_per_page);
  $view->nodes_per_block = intval($view->nodes_per_block);
  $view->menu_tab_weight = intval($view->menu_tab_weight);

  // re-order things as they were ordered on the form.
  foreach (array(
    'field',
    'argument',
    'filter',
    'sort',
    'exposed_filter',
  ) as $section) {
    views_ui_reorder($view->{$section});
  }
  $view_is_new = !$view->vid;
  $vid = _views_save_view($view);
  views_invalidate_cache();
  menu_rebuild();
  if ($form['vid']) {
    drupal_set_message(t('View successfully saved.'));
  }
  else {
    drupal_set_message(t('View successfully added.'));
  }
  if ($form['op'] == t('Save')) {
    $args = explode('/', $_GET['q']);
    if ($args[0] == 'admin' && $args[1] == 'build' && $args[2] == 'views') {
      return 'admin/build/views';
    }
    array_pop($args);
    return implode('/', $args);
  }
  if ($form['op'] == t('Save and edit') && $view_is_new) {
    return "admin/build/views/{$vid}/edit";
  }
}

/**
 * Validate a view with a type: list.
 */
function views_ui_plugin_validate_list($type, $view, $form) {

  // list (and table) modes require there to be at least 1 field active.
  if (is_array($view['field'])) {
    $fields = array_filter(array_keys($view['field']), 'is_numeric');
  }
  if (!$fields) {
    form_error($form["{$type}-info"][$type . '_type'], t('List and Table types require at least one field.'));
  }
  if (isset($view['field']['count'])) {
    $defaultsort = false;
    for ($i = 0; $i < $view['field']['count']; $i++) {
      if ($view['field'][$i]['defaultsort']) {
        if ($defaultsort) {
          form_error($form['field'][$i]['defaultsort'], t('You can only set on Default Sort on one field.'));
          break;
        }
        $defaultsort = true;
      }
    }
  }
}

/**
 * Validate a view with type: table.
 */
function views_ui_plugin_validate_table($type, $view, $form) {

  // pass thru to list cause for now they're the same.
  return views_ui_plugin_validate_list($type, $view, $form);
}

// ---------------------------------------------------------------------------
// View creator tool

/*
 * Get a true/false.
 */
function views_tf($val) {
  return $val ? 'TRUE' : 'FALSE';
}

/*
 * This function creates view code for a view.
 */
function views_create_view_code($vid) {
  $view = views_get_view($vid);
  if (!$view) {
    return t("View '%vid' not found.", array(
      '%vid' => $vid,
    ));
  }
  $requires = array();
  $output = "  \$view = new stdClass();\n";
  $output .= "  \$view->name = " . var_export($view->name, true) . ";\n";
  $output .= "  \$view->description = " . var_export($view->description, true) . ";\n";
  $output .= "  \$view->access = " . var_export($view->access, true) . ";\n";
  if (user_access('use PHP for block visibility')) {
    $output .= "  \$view->view_args_php = " . var_export($view->view_args_php, true) . ";\n";
  }

  // page items
  // Always emit these - needed for rendering embedded views, even if page is disabled.
  $output .= "  \$view->page = " . views_tf($view->page) . ";\n";
  $output .= "  \$view->page_title = " . var_export($view->page_title, true) . ";\n";
  $output .= "  \$view->page_header = " . var_export($view->page_header, true) . ";\n";
  $output .= "  \$view->page_header_format = " . var_export($view->page_header_format, true) . ";\n";
  $output .= "  \$view->page_footer = " . var_export($view->page_footer, true) . ";\n";
  $output .= "  \$view->page_footer_format = " . var_export($view->page_footer_format, true) . ";\n";
  $output .= "  \$view->page_empty = " . var_export($view->page_empty, true) . ";\n";
  $output .= "  \$view->page_empty_format = " . var_export($view->page_empty_format, true) . ";\n";
  $output .= "  \$view->page_type = " . var_export($view->page_type, true) . ";\n";
  $output .= "  \$view->url = " . var_export($view->url, true) . ";\n";
  $output .= "  \$view->use_pager = " . views_tf($view->use_pager) . ";\n";
  $output .= "  \$view->nodes_per_page = " . var_export($view->nodes_per_page, true) . ";\n";
  if ($view->menu) {
    $output .= "  \$view->menu = " . views_tf($view->menu) . ";\n";
    $output .= "  \$view->menu_title = " . var_export($view->menu_title, true) . ";\n";
    $output .= "  \$view->menu_tab = " . views_tf($view->menu_tab) . ";\n";
    $output .= "  \$view->menu_tab_weight = " . var_export($view->menu_tab_weight, true) . ";\n";
    $output .= "  \$view->menu_tab_default = " . views_tf($view->menu_tab_default) . ";\n";
    $output .= "  \$view->menu_tab_default_parent = " . var_export($view->menu_tab_default_parent, true) . ";\n";
    $output .= "  \$view->menu_tab_default_parent_type = " . var_export($view->menu_tab_default_parent_type, true) . ";\n";
    $output .= "  \$view->menu_parent_tab_weight = " . var_export($view->menu_parent_tab_weight, true) . ";\n";
    $output .= "  \$view->menu_parent_title = " . var_export($view->menu_parent_title, true) . ";\n";
  }
  if ($view->block) {
    $output .= "  \$view->block = " . views_tf($view->block) . ";\n";
    $output .= "  \$view->block_title = " . var_export($view->block_title, true) . ";\n";
    $output .= "  \$view->block_header = " . var_export($view->block_header, true) . ";\n";
    $output .= "  \$view->block_header_format = " . var_export($view->block_header_format, true) . ";\n";
    $output .= "  \$view->block_footer = " . var_export($view->block_footer, true) . ";\n";
    $output .= "  \$view->block_footer_format = " . var_export($view->block_footer_format, true) . ";\n";
    $output .= "  \$view->block_empty = " . var_export($view->block_empty, true) . ";\n";
    $output .= "  \$view->block_empty_format = " . var_export($view->block_empty_format, true) . ";\n";
    $output .= "  \$view->block_type = " . var_export($view->block_type, true) . ";\n";
    $output .= "  \$view->nodes_per_block = " . var_export($view->nodes_per_block, true) . ";\n";
    $output .= "  \$view->block_more = " . views_tf($view->block_more) . ";\n";
    $output .= "  \$view->block_use_page_header = " . views_tf($view->block_use_page_header) . ";\n";
    $output .= "  \$view->block_use_page_footer = " . views_tf($view->block_use_page_footer) . ";\n";
    $output .= "  \$view->block_use_page_empty = " . views_tf($view->block_use_page_empty) . ";\n";
  }
  $output .= "  \$view->sort = array(\n";
  foreach ($view->sort as $sort) {
    $output .= "    array(\n";
    $fieldbits = explode('.', $sort['field']);
    $output .= "      'tablename' => " . var_export($fieldbits[0], true) . ",\n";
    $output .= "      'field' => " . var_export($fieldbits[1], true) . ",\n";
    $output .= "      'sortorder' => " . var_export($sort['sortorder'], true) . ",\n";
    $output .= "      'options' => " . var_export($sort['options'], true) . ",\n";
    $output .= "    ),\n";
    $requires[$fieldbits[0]] = 1;
  }
  $output .= "  );\n";
  $output .= "  \$view->argument = array(\n";
  foreach ($view->argument as $argument) {
    $output .= "    array(\n";
    $output .= "      'type' => " . var_export($argument['type'], true) . ",\n";
    $output .= "      'argdefault' => " . var_export($argument['argdefault'], true) . ",\n";
    $output .= "      'title' => " . var_export($argument['title'], true) . ",\n";
    $output .= "      'options' => " . var_export($argument['options'], true) . ",\n";
    $output .= "      'wildcard' => " . var_export($argument['wildcard'], true) . ",\n";
    $output .= "      'wildcard_substitution' => " . var_export($argument['wildcard_substitution'], true) . ",\n";
    $output .= "    ),\n";
  }
  $output .= "  );\n";
  $output .= "  \$view->field = array(\n";
  foreach ($view->field as $field) {
    $output .= "    array(\n";
    $output .= "      'tablename' => " . var_export($field['tablename'], true) . ",\n";
    $output .= "      'field' => " . var_export($field['field'], true) . ",\n";
    $output .= "      'label' => " . var_export($field['label'], true) . ",\n";
    if ($field['handler']) {
      $output .= "      'handler' => " . var_export($field['handler'], true) . ",\n";
    }
    if ($field['sortable']) {
      $output .= "      'sortable' => " . var_export($field['sortable'], true) . ",\n";
    }
    if ($field['defaultsort']) {
      $output .= "      'defaultsort' => " . var_export($field['defaultsort'], true) . ",\n";
    }
    if ($field['options']) {
      $output .= "      'options' => " . var_export($field['options'], true) . ",\n";
    }
    $output .= "    ),\n";
    $requires[$field['tablename']] = 1;
  }
  $output .= "  );\n";
  $output .= "  \$view->filter = array(\n";
  foreach ($view->filter as $filter) {
    $output .= "    array(\n";
    $fieldbits = explode('.', $filter['field']);
    $output .= "      'tablename' => " . var_export($fieldbits[0], true) . ",\n";
    $output .= "      'field' => " . var_export($fieldbits[1], true) . ",\n";
    $output .= "      'operator' => " . var_export($filter['operator'], true) . ",\n";
    $output .= "      'options' => " . var_export($filter['options'], true) . ",\n";
    $output .= "      'value' => " . var_export($filter['value'], true) . ",\n";
    $output .= "    ),\n";
    $requires[$fieldbits[0]] = 1;
  }
  $output .= "  );\n";
  $output .= "  \$view->exposed_filter = array(\n";
  foreach ($view->exposed_filter as $filter) {
    $output .= "    array(\n";
    $fieldbits = explode('.', $filter['field']);
    $output .= "      'tablename' => " . var_export($fieldbits[0], true) . ",\n";
    $output .= "      'field' => " . var_export($fieldbits[1], true) . ",\n";
    $output .= "      'label' => " . var_export($filter['label'], true) . ",\n";
    $output .= "      'optional' => " . var_export($filter['optional'], true) . ",\n";
    $output .= "      'is_default' => " . var_export($filter['is_default'], true) . ",\n";
    $output .= "      'operator' => " . var_export($filter['operator'], true) . ",\n";
    $output .= "      'single' => " . var_export($filter['single'], true) . ",\n";
    $output .= "    ),\n";
    $requires[$fieldbits[0]] = 1;
  }
  $output .= "  );\n";
  $output .= "  \$view->requires = array(" . implode(', ', array_keys($requires)) . ");\n";
  $output .= "  \$views[\$view->name] = \$view;\n";
  return $output;
}

Functions

Namesort descending Description
theme_views_edit_view Display the form built by _views_view_form()
theme_views_imagebutton
views_create_view_code
views_edit_view Display all the guts of a view in a form for editing.
views_edit_view_submit Handle submit buttons on a view form.
views_edit_view_validate Validate that a view sent via form is OK.
views_elements Custom form element to do our nice images.
views_imagebutton_value
views_tf
views_ui_add_add_button Add the 'add' button for a section into the form
views_ui_add_argument Add all the info for a single argument into the form.
views_ui_add_button Add a single button to a form.
views_ui_add_buttons Add the up, down, top, bottom, delete buttons to a form.
views_ui_add_exposed_filter Add all the info for a single exposed filter into the form.
views_ui_add_field Add all the info for a single field into the form.
views_ui_add_filter Add all the info for a single filter into the form.
views_ui_add_menu_items
views_ui_add_section Add one of the list sections to the form.
views_ui_add_sort Add all the info for a single sort into the form.
views_ui_admin_add_page
views_ui_admin_clone_page
views_ui_admin_delete_confirm
views_ui_admin_delete_confirm_submit
views_ui_admin_disable_page
views_ui_admin_edit_page
views_ui_admin_enable_page
views_ui_admin_export_page
views_ui_admin_import
views_ui_admin_import_page
views_ui_admin_import_submit
views_ui_admin_page
views_ui_admin_tools
views_ui_admin_tools_submit
views_ui_build_form separately build a piece of the form
views_ui_help
views_ui_menu
views_ui_perm
views_ui_plugin_validate_list Validate a view with a type: list.
views_ui_plugin_validate_table Validate a view with type: table.
views_ui_render_section Render one of the dynamic sections on our form.
views_ui_render_section_add Render the add buttons for one of the dynamic sections on our form.
views_ui_reorder
views_ui_setup_widget Set up the dynamic #options on a widget
_views_check_ops Figure out if one of the add buttons on a form were clicked, and handle it.
_views_check_sub_ops Figure out which of the many, many buttons on a form were clicked and handle it.
_views_get_arguments_default Select box entries for argument defaults.
_views_get_default_view
_views_move_bottom Move an item to the end of an array.
_views_move_down Move an item down in an array.
_views_move_top Move an item to the front of an array.
_views_move_up Move an item up in an array.
_views_sortorders Select box entries for sort ordering.
_views_swap Swap two items in an array.
_views_ui_help_add