You are here

function vertical_tabs_form_configure in Vertical Tabs 6

1 string reference to 'vertical_tabs_form_configure'
vertical_tabs_form_info in ./vertical_tabs.module
Implements hook_form_controller_info().

File

./vertical_tabs.module, line 489
Provides vertical tabs capability for fieldsets in forms.

Code

function vertical_tabs_form_configure(&$complete_form, $form_id, $context) {
  if ($elements = vertical_tabs_get_form_elements($context['form'])) {

    // Fetch the configuration.
    $config = vertical_tabs_get_config($form_id);

    // Check if this form is currently vertical tabified.
    $is_form_tabified = isset($context['form']['vertical_tabs']) || isset($context['form']['#pre_render']) && in_array('vertical_tabs_form_pre_render', $context['form']['#pre_render']);
    $form['status'] = array(
      '#type' => 'checkbox',
      '#title' => t('Vertical tabify this form.'),
      '#default_value' => isset($config) ? $config !== FALSE : $is_form_tabified,
    );

    // Merge default values and correct non-key-matching values.
    // @todo Keep settings for non-accessible fieldsets set by more priviledged users?
    $defaults = is_array($config) ? $config : array();
    $options = array();
    foreach ($elements as $key => $element) {
      $options[$key] = $element['#title'];
      if (!isset($defaults[$key]) && !empty($element['#group'])) {
        $defaults[$key] = $key;
      }
    }
    $form['fieldsets'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Include the following elements in the vertical tabs'),
      '#options' => $options,
      '#default_value' => $defaults,
    );
    if (module_exists('ctools')) {
      ctools_include('dependent');
      $form['fieldsets'] += array(
        '#process' => array(
          'expand_checkboxes',
          'ctools_dependent_process',
        ),
        '#dependency' => array(
          'edit-vertical-tabs-form-status' => array(
            TRUE,
          ),
        ),
        '#prefix' => '<div><div id="edit-vertical-tabs-form-fieldsets-wrapper">',
        '#suffix' => '</div></div>',
      );
    }
    $complete_form['#submit'][] = 'vertical_tabs_form_configure_submit';
    return $form;
  }
}