You are here

function ViewsUiBaseViewsWizard::build_form in Views (for Drupal 7) 7.3

For AJAX callbacks to build other elements in the "show" form.

Overrides ViewsWizardInterface::build_form

File

plugins/views_wizard/views_ui_base_views_wizard.class.php, line 85
Provides the interface and base class for Views Wizard plugins.

Class

ViewsUiBaseViewsWizard
A very generic Views Wizard class - can be constructed for any base table.

Code

function build_form($form, &$form_state) {
  $style_options = views_fetch_plugin_names('style', 'normal', array(
    $this->base_table,
  ));
  $feed_row_options = views_fetch_plugin_names('row', 'feed', array(
    $this->base_table,
  ));
  $path_prefix = url(NULL, array(
    'absolute' => TRUE,
  )) . (variable_get('clean_url', 0) ? '' : '?q=');

  // Add filters and sorts which apply to the view as a whole.
  $this
    ->build_filters($form, $form_state);
  $this
    ->build_sorts($form, $form_state);
  $form['displays']['page'] = array(
    '#type' => 'fieldset',
    '#attributes' => array(
      'class' => array(
        'views-attachment',
        'fieldset-no-legend',
      ),
    ),
    '#tree' => TRUE,
  );
  $form['displays']['page']['create'] = array(
    '#title' => t('Create a page'),
    '#type' => 'checkbox',
    '#attributes' => array(
      'class' => array(
        'strong',
      ),
    ),
    '#default_value' => TRUE,
    '#id' => 'edit-page-create',
  );

  // All options for the page display are included in this container so they
  // can be hidden en masse when the "Create a page" checkbox is unchecked.
  $form['displays']['page']['options'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'options-set',
      ),
    ),
    '#dependency' => array(
      'edit-page-create' => array(
        1,
      ),
    ),
    '#pre_render' => array(
      'ctools_dependent_pre_render',
    ),
    '#prefix' => '<div><div id="edit-page-wrapper">',
    '#suffix' => '</div></div>',
    '#parents' => array(
      'page',
    ),
  );
  $form['displays']['page']['options']['title'] = array(
    '#title' => t('Page title'),
    '#type' => 'textfield',
  );
  $form['displays']['page']['options']['path'] = array(
    '#title' => t('Path'),
    '#type' => 'textfield',
    '#field_prefix' => $path_prefix,
  );
  $form['displays']['page']['options']['style'] = array(
    '#type' => 'fieldset',
    '#attributes' => array(
      'class' => array(
        'container-inline',
        'fieldset-no-legend',
      ),
    ),
  );

  // Create the dropdown for choosing the display format.
  $form['displays']['page']['options']['style']['style_plugin'] = array(
    '#title' => t('Display format'),
    '#help_topic' => 'style',
    '#type' => 'select',
    '#options' => $style_options,
  );
  $style_form =& $form['displays']['page']['options']['style'];
  $style_form['style_plugin']['#default_value'] = views_ui_get_selected($form_state, array(
    'page',
    'style',
    'style_plugin',
  ), 'default', $style_form['style_plugin']);

  // Changing this dropdown updates $form['displays']['page']['options'] via
  // AJAX.
  views_ui_add_ajax_trigger($style_form, 'style_plugin', array(
    'displays',
    'page',
    'options',
  ));
  $this
    ->build_form_style($form, $form_state, 'page');
  $form['displays']['page']['options']['items_per_page'] = array(
    '#title' => t('Items to display'),
    '#type' => 'textfield',
    '#default_value' => '10',
    '#size' => 5,
    '#element_validate' => array(
      'views_element_validate_integer',
    ),
  );
  $form['displays']['page']['options']['pager'] = array(
    '#title' => t('Use a pager'),
    '#type' => 'checkbox',
    '#default_value' => TRUE,
  );
  $form['displays']['page']['options']['link'] = array(
    '#title' => t('Create a menu link'),
    '#type' => 'checkbox',
    '#id' => 'edit-page-link',
  );
  $form['displays']['page']['options']['link_properties'] = array(
    '#type' => 'container',
    '#dependency' => array(
      'edit-page-link' => array(
        1,
      ),
    ),
    '#pre_render' => array(
      'ctools_dependent_pre_render',
    ),
    '#prefix' => '<div id="edit-page-link-properties-wrapper">',
    '#suffix' => '</div>',
  );
  if (module_exists('menu')) {
    $menu_options = menu_get_menus();
  }
  else {

    // These are not yet translated.
    $menu_options = menu_list_system_menus();
    foreach ($menu_options as $name => $title) {
      $menu_options[$name] = t($title);
    }
  }
  $form['displays']['page']['options']['link_properties']['menu_name'] = array(
    '#title' => t('Menu'),
    '#type' => 'select',
    '#options' => $menu_options,
  );
  $form['displays']['page']['options']['link_properties']['title'] = array(
    '#title' => t('Link text'),
    '#type' => 'textfield',
  );

  // Only offer a feed if we have at least one available feed row style.
  if ($feed_row_options) {
    $form['displays']['page']['options']['feed'] = array(
      '#title' => t('Include an RSS feed'),
      '#type' => 'checkbox',
      '#id' => 'edit-page-feed',
    );
    $form['displays']['page']['options']['feed_properties'] = array(
      '#type' => 'container',
      '#dependency' => array(
        'edit-page-feed' => array(
          1,
        ),
      ),
      '#pre_render' => array(
        'ctools_dependent_pre_render',
      ),
      '#prefix' => '<div id="edit-page-feed-properties-wrapper">',
      '#suffix' => '</div>',
    );
    $form['displays']['page']['options']['feed_properties']['path'] = array(
      '#title' => t('Feed path'),
      '#type' => 'textfield',
      '#field_prefix' => $path_prefix,
    );

    // This will almost never be visible.
    $form['displays']['page']['options']['feed_properties']['row_plugin'] = array(
      '#title' => t('Feed row style'),
      '#type' => 'select',
      '#options' => $feed_row_options,
      '#default_value' => key($feed_row_options),
      '#access' => count($feed_row_options) > 1,
      '#dependency' => array(
        'edit-page-feed' => array(
          1,
        ),
      ),
      '#pre_render' => array(
        'ctools_dependent_pre_render',
      ),
      '#prefix' => '<div id="edit-page-feed-properties-row-plugin-wrapper">',
      '#suffix' => '</div>',
    );
  }
  $form['displays']['block'] = array(
    '#type' => 'fieldset',
    '#attributes' => array(
      'class' => array(
        'views-attachment',
        'fieldset-no-legend',
      ),
    ),
    '#tree' => TRUE,
  );
  $form['displays']['block']['create'] = array(
    '#title' => t('Create a block'),
    '#type' => 'checkbox',
    '#attributes' => array(
      'class' => array(
        'strong',
      ),
    ),
    '#id' => 'edit-block-create',
  );

  // All options for the block display are included in this container so they
  // can be hidden en masse when the "Create a block" checkbox is unchecked.
  $form['displays']['block']['options'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'options-set',
      ),
    ),
    '#dependency' => array(
      'edit-block-create' => array(
        1,
      ),
    ),
    '#pre_render' => array(
      'ctools_dependent_pre_render',
    ),
    '#prefix' => '<div id="edit-block-wrapper">',
    '#suffix' => '</div>',
    '#parents' => array(
      'block',
    ),
  );
  $form['displays']['block']['options']['title'] = array(
    '#title' => t('Block title'),
    '#type' => 'textfield',
  );
  $form['displays']['block']['options']['style'] = array(
    '#type' => 'fieldset',
    '#attributes' => array(
      'class' => array(
        'container-inline',
        'fieldset-no-legend',
      ),
    ),
  );

  // Create the dropdown for choosing the display format.
  $form['displays']['block']['options']['style']['style_plugin'] = array(
    '#title' => t('Display format'),
    '#help_topic' => 'style',
    '#type' => 'select',
    '#options' => $style_options,
  );
  $style_form =& $form['displays']['block']['options']['style'];
  $style_form['style_plugin']['#default_value'] = views_ui_get_selected($form_state, array(
    'block',
    'style',
    'style_plugin',
  ), 'default', $style_form['style_plugin']);

  // Changing this dropdown updates $form['displays']['block']['options'] via
  // AJAX.
  views_ui_add_ajax_trigger($style_form, 'style_plugin', array(
    'displays',
    'block',
    'options',
  ));
  $this
    ->build_form_style($form, $form_state, 'block');
  $form['displays']['block']['options']['items_per_page'] = array(
    '#title' => t('Items per page'),
    '#type' => 'textfield',
    '#default_value' => '5',
    '#size' => 5,
    '#element_validate' => array(
      'views_element_validate_integer',
    ),
  );
  $form['displays']['block']['options']['pager'] = array(
    '#title' => t('Use a pager'),
    '#type' => 'checkbox',
    '#default_value' => FALSE,
  );
  return $form;
}