1 views_ui_base_views_wizard.php ViewsUiBaseViewsWizard::build_form($form, &$form_state)

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

Overrides ViewsWizardInterface::build_form

File

core/modules/views_ui/wizards/views_ui_base_views_wizard.php, line 78
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)) . (config_get('system.core', 'clean_url') ? '' : '?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',
        'edit-page-style-wrapper',
      ),
    ),
    '#tree' => TRUE,
  );
  $form['displays']['page']['create'] = array(
    '#title' => t('Create a page'),
    '#type' => 'checkbox',
    '#attributes' => array('class' => array('strong')),
    '#default_value' => (bool) config_get('views_ui.settings', 'wizard_default_display.page'),
    '#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', 'form-wrapper'),),
    '#states' => array(
      'visible' => array(
        ':input[name="page[create]"]' => array('checked' => TRUE),
      ),
    ),
    '#prefix' => '<div><div class="edit-page-style-inner-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' => 'number',
    '#default_value' => '10',
    '#size' => 5,
    '#min' => 0,
    '#step' => 1,
  );
  $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',
    '#states' => array(
      'visible' => array(
        ':input[name="page[link]"]' => array('checked' => TRUE),
      ),
    ),
    '#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,
  );
  // If the primary navigation menu exists, set it as default.
  if (array_key_exists('main-menu', $menu_options)) {
    $form['displays']['page']['options']['link_properties']['menu_name']['#default_value'] = array('main-menu');
  }
  $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',
      '#states' => array(
        'visible' => array(
          ':input[name="page[feed]"]' => array('checked' => TRUE),
        ),
      ),
      '#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),
      '#states' => array(
        'visible' => array(
          ':input[name="page[feed]"]' => array('checked' => TRUE),
        ),
      ),
      '#prefix' => '<div id="edit-page-feed-properties-row-plugin-wrapper">',
      '#suffix' => '</div>',
    );
  }

  $form['displays']['block'] = array(
    '#type' => 'fieldset',
    '#attributes' => array(
      'class' => array(
        'views-attachment',
        'edit-block-style-wrapper',
      ),
    ),
    '#tree' => TRUE,
  );
  $form['displays']['block']['create'] = array(
    '#title' => t('Create a block'),
    '#type' => 'checkbox',
    '#attributes' => array('class' => array('strong')),
    '#default_value' => (bool) config_get('views_ui.settings', 'wizard_default_display.block'),
    '#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', 'form-wrapper'),),
    '#states' => array(
      'visible' => array(
        ':input[name="block[create]"]' => array('checked' => TRUE),
      ),
    ),
    '#prefix' => '<div class="edit-block-style-inner-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 to display'),
    '#type' => 'number',
    '#default_value' => '5',
    '#size' => 5,
    '#min' => 0,
    '#step' => 1,
  );
  $form['displays']['block']['options']['pager'] = array(
    '#title' => t('Use a pager'),
    '#type' => 'checkbox',
    '#default_value' => FALSE,
  );

  return $form;
}