You are here

function views_edit_view in Views (for Drupal 7) 5

Display all the guts of a view in a form for editing.

6 string references to 'views_edit_view'
views_ui_admin_add_page in ./views_ui.module
views_ui_admin_clone_page in ./views_ui.module
views_ui_admin_edit_page in ./views_ui.module
views_ui_admin_import_page in ./views_ui.module
views_ui_admin_import_submit in ./views_ui.module

... See full list

File

./views_ui.module, line 764

Code

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;
}