Same name in other branches
  1. 7.x-2.x includes/admin.inc \_quicktabs_admin_main_form()
  2. 8.x-1.x quicktabs.admin.inc \_quicktabs_admin_main_form()

The main section of admin page.

1 call to _quicktabs_admin_main_form()
quicktabs_form in ./quicktabs.admin.inc
Build the quicktab creation and edit form.

File

./quicktabs.admin.inc, line 130

Code

function _quicktabs_admin_main_form($form_state, &$qt) {
    // The contents of $qt will either come from the db or from $form_state.
    if (isset($form_state['values']['title'])) {
        $qt = _quicktabs_convert_form_to_quicktabs($form_state);
    }
    $form['title'] = array(
        '#title' => t('Title'),
        '#description' => t('This will appear as the block title.'),
        '#type' => 'textfield',
        '#default_value' => isset($qt->title) ? $qt->title : '',
        '#weight' => -9,
        '#required' => TRUE,
    );
    $form['machine_name'] = array(
        '#type' => 'machine_name',
        '#maxlength' => 32,
        '#machine_name' => array(
            'exists' => 'quicktabs_machine_name_exists',
            'source' => array(
                'title',
            ),
        ),
        '#description' => t('A unique machine-readable name for this Quicktabs instance. It must only contain lowercase letters, numbers, and underscores. The machine name will be used internally by Quicktabs and will be used in the CSS ID of your Quicktabs block.'),
        '#weight' => -8,
    );
    if (!empty($qt->machine_name)) {
        $form['machine_name']['#default_value'] = $qt->machine_name;
        $form['machine_name']['#disabled'] = TRUE;
        $form['machine_name']['#value'] = $qt->machine_name;
    }
    ctools_include('plugins');
    $renderers = ctools_get_plugins('quicktabs', 'renderers');
    $renderer_options = array();
    foreach ($renderers as $name => $info) {
        if ($class = ctools_plugin_load_class('quicktabs', 'renderers', $name, 'handler')) {
            // Add the renderer to the dropdown list of renderers
            $renderer_options[$name] = $name;
            // Get the renderer's options form elements
            // PHP 5.2 doesn't support $class::staticMethod() syntax, so we have to
            // use call_user_func_array() until PHP 5.3 is required.
            $renderer_form_options[$name] = call_user_func_array(array(
                $class,
                'optionsForm',
            ), array(
                $qt,
            ));
        }
    }
    ksort($renderer_options);
    $form['renderer'] = array(
        '#type' => 'select',
        '#title' => t('Renderer'),
        '#options' => $renderer_options,
        '#default_value' => isset($qt->renderer) ? $qt->renderer : 'quicktabs',
        '#description' => t('Choose how to render the content.'),
        '#weight' => -7,
    );
    // Add the renderer options form elements to the form, to be shown only if the
    // renderer in question is selected.
    $form['options'] = array(
        '#tree' => TRUE,
        '#weight' => -6,
    );
    foreach ($renderer_form_options as $renderer => $options) {
        foreach ($options as &$option) {
            $option['#states'] = array(
                'visible' => array(
                    ':input[name="renderer"]' => array(
                        'value' => $renderer,
                    ),
                ),
            );
        }
        $form['options'][$renderer] = $options;
    }
    $styles = module_invoke_all('quicktabs_tabstyles');
    if (count($styles)) {
        $style_options = array();
        // The keys used for options must be valid html IDs.
        foreach ($styles as $style) {
            $style_options[$style] = $style;
        }
        ksort($style_options);
        $form['style'] = array(
            '#type' => 'select',
            '#title' => t('Style'),
            '#options' => array(
                'nostyle' => t('No style'),
            ) + array(
                'default' => t('Default style'),
            ) + $style_options,
            '#default_value' => isset($qt->style) ? $qt->style : 'default',
            '#description' => t('Choose the quicktab style.'),
            '#states' => array(
                'visible' => array(
                    ':input[name="renderer"]' => array(
                        'value' => 'quicktabs',
                    ),
                ),
            ),
            '#weight' => -6,
        );
    }
    else {
        $form['style'] = array(
            '#type' => 'value',
            '#value' => 'nostyle',
        );
    }
    $form['ajax'] = array(
        '#type' => 'radios',
        '#title' => t('Ajax'),
        '#options' => array(
            TRUE => t('Yes') . ': ' . t('Load only the first tab on page view'),
            FALSE => t('No') . ': ' . t('Load all tabs on page view.'),
        ),
        '#default_value' => isset($qt->ajax) ? $qt->ajax : 0,
        '#description' => t('Choose how the content of tabs should be loaded.<p>By choosing "Yes", only the first tab will be loaded when the page first viewed. Content for other tabs will be loaded only when the user clicks the other tab. This will provide faster initial page loading, but subsequent tab clicks will be slower. This can place less load on a server.</p><p>By choosing "No", all tabs will be loaded when the page is first viewed. This will provide slower initial page loading, and more server load, but subsequent tab clicks will be faster for the user. Use with care if you have heavy views.</p><p>Warning: if you enable Ajax, any block you add to this quicktabs block will be accessible to anonymous users, even if you place role restrictions on the quicktabs block. Do not enable Ajax if the quicktabs block includes any blocks with potentially sensitive information.</p>'),
        '#states' => array(
            'visible' => array(
                ':input[name="renderer"]' => array(
                    'value' => 'quicktabs',
                ),
            ),
        ),
        '#weight' => -5,
    );
    $form['hide_empty_tabs'] = array(
        '#type' => 'checkbox',
        '#title' => t('Hide empty tabs'),
        '#default_value' => isset($qt->hide_empty_tabs) ? $qt->hide_empty_tabs : 0,
        '#description' => t('Empty and restricted tabs will not be displayed. Could be useful when the tab content is not accessible.<br />This option does not work in ajax mode.'),
        '#weight' => -4,
    );
    // Add a wrapper for the tabs and Add Another Tab button.
    $form['qt_wrapper'] = array(
        '#tree' => FALSE,
        '#weight' => -3,
        '#prefix' => '<div class="clear-block" id="quicktabs-tabs-wrapper">',
        '#suffix' => '</div>',
    );
    $form['qt_wrapper']['tabs'] = array(
        '#tree' => TRUE,
        '#prefix' => '<div id="quicktab-tabs">',
        '#suffix' => '</div>',
        '#theme' => 'quicktabs_admin_form_tabs',
    );
    $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'),
        '#attributes' => array(
            'class' => array(
                'add-tab',
            ),
            'title' => t('Click here to add more tabs.'),
        ),
        '#weight' => 1,
        '#submit' => array(
            'quicktabs_more_tabs_submit',
        ),
        '#ajax' => array(
            'callback' => 'quicktabs_ajax_callback',
            'wrapper' => 'quicktab-tabs',
            'effect' => 'fade',
        ),
        '#limit_validation_errors' => array(),
    );
    $form['actions'] = array(
        '#type' => 'actions',
    );
    $form['actions']['submit_form'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
    );
    return $form;
}