You are here

function quicktabs_form in Quick Tabs 6

Same name and namespace in other branches
  1. 5 quicktabs.module \quicktabs_form()
  2. 6.3 includes/admin.inc \quicktabs_form()
  3. 6.2 includes/admin.inc \quicktabs_form()
  4. 7.3 quicktabs.admin.inc \quicktabs_form()
  5. 7.2 includes/admin.inc \quicktabs_form()

build the Quick Tabs creation and edit form

2 string references to 'quicktabs_form'
quicktabs_block_edit in ./quicktabs.module
quicktabs_new in ./quicktabs.module

File

./quicktabs.module, line 125

Code

function quicktabs_form($form_state = NULL, $quicktabs = NULL) {

  // Add our JS file, which has some Drupal core JS overrides, and ensures ahah behaviours get re-attached
  drupal_add_js(drupal_get_path('module', 'quicktabs') . '/js/quicktabs_ahah.js', 'footer');
  $form = array(
    '#cache' => TRUE,
  );

  // the contents of $quicktabs will either come from the db or from $form_state
  if (isset($form_state['quicktabs'])) {
    $quicktabs = $form_state['quicktabs'] + (array) $quicktabs;
  }
  $form['title'] = array(
    '#title' => t('Block Title'),
    '#type' => 'textfield',
    '#description' => t('The title of the whole block'),
    '#default_value' => $quicktabs['title'] ? $quicktabs['title'] : '',
    '#weight' => -5,
  );
  $tabcontent = $quicktabs['tabs'];
  $formtype = $quicktabs['formtype'];
  if ($formtype == 'edit') {
    $form['qtid'] = array(
      '#type' => 'hidden',
      '#value' => $quicktabs['qtid'],
    );
  }
  if (isset($form_state['qt_count'])) {
    $qt_count = $form_state['qt_count'];
  }
  else {
    $qt_count = max(2, empty($tabcontent) ? 2 : count($tabcontent));
  }

  // Add a wrapper for the tabs and Add Another Tab button.
  $form['qt_wrapper'] = array(
    '#tree' => FALSE,
    '#weight' => -4,
    '#prefix' => '<div class="clear-block" id="quicktabs-tabs-wrapper">',
    '#suffix' => '</div>',
  );
  $form['qt_wrapper']['tabs'] = array(
    '#prefix' => '<div id="quicktabs-tabs">',
    '#suffix' => '</div>',
    '#theme' => 'qt_tabs',
  );

  // Add the current tabs to the form.
  for ($delta = 0; $delta < $qt_count; $delta++) {
    $weight = isset($tabcontent[$delta]['tabweight']) ? $tabcontent[$delta]['tabweight'] : $delta - 10;
    $title = isset($tabcontent[$delta]['tabtext']) ? $tabcontent[$delta]['tabtext'] : '';
    $type = isset($tabcontent[$delta]['tabtype']) ? $tabcontent[$delta]['tabtype'] : 'block';
    $bid = isset($tabcontent[$delta]['bid']) ? $tabcontent[$delta]['bid'] : NULL;
    $hide_title = isset($tabcontent[$delta]['hide_title']) ? $tabcontent[$delta]['hide_title'] : 1;
    $vid = isset($tabcontent[$delta]['vid']) ? $tabcontent[$delta]['vid'] : 'default';
    $args = isset($tabcontent[$delta]['args']) ? $tabcontent[$delta]['args'] : NULL;
    $display = isset($tabcontent[$delta]['display']) ? $tabcontent[$delta]['display'] : 'default';
    $form['qt_wrapper']['tabs'][$delta] = _quicktabs_form($delta, $weight, $title, $type, $bid, $hide_title, $vid, $args, $display);
  }
  $form['qt_wrapper']['tabs_more'] = array(
    '#type' => 'submit',
    '#prefix' => '<div id="add-more-tabs-button">',
    '#suffix' => '<label for="edit-tabs-more">' . t('Add tab') . '</label></div>',
    '#value' => t('More tabs'),
    '#description' => t("Click here to add more tabs."),
    '#attributes' => array(
      'class' => 'add-tab',
    ),
    '#weight' => 1,
    '#submit' => array(
      'qt_more_tabs_submit',
    ),
    // If no javascript action.
    '#ahah' => array(
      'path' => 'quicktabs/ahah',
      'wrapper' => 'quicktabs-tabs',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );
  $form['qt_wrapper']['remove'] = array(
    '#type' => 'submit',
    '#prefix' => '<div id="delete-tabs-button">',
    '#suffix' => '<label for="edit-remove">' . t('Remove last tab') . '</label></div>',
    '#value' => t('remove'),
    '#attributes' => array(
      'class' => 'delete-tab',
    ),
    '#submit' => array(
      'qt_remove_tab_submit',
    ),
    '#ahah' => array(
      'path' => 'quicktabs/ahah',
      'wrapper' => 'quicktabs-tabs',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}