You are here

function faq_categories_settings_form in Frequently Asked Questions 7.2

Same name and namespace in other branches
  1. 5.2 faq.module \faq_categories_settings_form()
  2. 5 faq.module \faq_categories_settings_form()
  3. 6 faq.admin.inc \faq_categories_settings_form()
  4. 7 faq.admin.inc \faq_categories_settings_form()

Define the elements for the FAQ Settings page - categories tab.

Return value

The form code inside the $form array.

1 string reference to 'faq_categories_settings_form'
faq_menu in ./faq.module
Implements hook_menu().

File

./faq.admin.inc, line 265
Administrative page callbacks for the faq module.

Code

function faq_categories_settings_form($form, &$form_state) {
  $categorization_enabled = variable_get('faq_use_categories', FALSE);
  $vocabularies = array();
  $vocab_omit = array();
  $vocab_options = array();

  // Display error messages if the taxonomy module isn't enabled or if there is
  // no valid FAQ vocabulary.
  if (!module_exists("taxonomy")) {
    drupal_set_message(t('Categorization of questions will not work without the "taxonomy" module being enabled.'), 'error');
  }
  else {
    $vocabularies = taxonomy_get_vocabularies('faq');
    $vocab_omit = variable_get('faq_omit_vocabulary', array());
    foreach ($vocabularies as $vid => $vobj) {
      $vocab_options[$vid] = $vobj->name;
    }
  }

  // Set up a hidden variable.
  $form['faq_display'] = array(
    '#type' => 'hidden',
    '#value' => variable_get('faq_display', 'questions_top'),
  );
  $form['faq_use_categories'] = array(
    '#type' => 'checkbox',
    '#title' => t('Categorize questions'),
    '#description' => t('This allows the user to display the questions according to the categories configured on the add/edit FAQ page.  Use of sub-categories is only recommended for large lists of questions.  The Taxonomy module must be enabled.'),
    '#default_value' => $categorization_enabled,
  );
  $category_options['none'] = t("Don't display");
  $category_options['categories_inline'] = t('Categories inline');
  $category_options['hide_qa'] = t('Clicking on category opens/hides questions and answers under category');
  $category_options['new_page'] = t('Clicking on category opens the questions/answers in a new page');
  $form['faq_category_display'] = array(
    '#type' => 'radios',
    '#options' => $category_options,
    '#title' => t('Categories layout'),
    '#description' => t('This controls how the categories are displayed on the page and what happens when someone clicks on the category.'),
    '#default_value' => variable_get('faq_category_display', 'categories_inline'),
    '#states' => array(
      'visible' => array(
        ':input[name="faq_use_categories"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['faq_category_misc'] = array(
    '#type' => 'fieldset',
    '#title' => t('Miscellaneous layout settings'),
    '#collapsible' => TRUE,
    '#states' => array(
      'visible' => array(
        ':input[name="faq_use_categories"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['faq_category_misc']['faq_category_listing'] = array(
    '#type' => 'select',
    '#options' => array(
      'ol' => t('Ordered list'),
      'ul' => t('Unordered list'),
    ),
    '#title' => t('Categories listing style'),
    '#description' => t('This allows to select how the categories listing is presented. An ordered listing would number the categories, whereas an unordered list will have a bullet to the left of each category.'),
    '#default_value' => variable_get('faq_category_listing', 'ul'),
    '#states' => array(
      'visible' => array(
        ':input[name="faq_category_display"]' => array(
          'value' => 'new_page',
        ),
      ),
    ),
  );
  $form['faq_category_misc']['faq_category_hide_qa_accordion'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use accordion effect'),
    '#description' => t('This enables an "accordion" style effect where when a category is clicked, the questions appears beneath, and is then hidden when another category is opened.'),
    '#default_value' => variable_get('faq_category_hide_qa_accordion', FALSE),
    '#states' => array(
      'visible' => array(
        ':input[name="faq_category_display"]' => array(
          'value' => 'hide_qa',
        ),
      ),
    ),
  );
  $form['faq_category_misc']['faq_count'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show FAQ count'),
    '#description' => t('This displays the number of questions in a category after the category name.'),
    '#default_value' => variable_get('faq_count', FALSE),
  );
  $form['faq_category_misc']['faq_answer_category_name'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display category name for answers'),
    '#description' => t('This allows the user to toggle the visibility of the category name above each answer section.'),
    '#default_value' => variable_get('faq_answer_category_name', FALSE),
    '#states' => array(
      'visible' => array(
        ':input[name="faq_display"]' => array(
          'value' => 'hide_qa',
        ),
      ),
    ),
  );
  $form['faq_category_misc']['faq_group_questions_top'] = array(
    '#type' => 'checkbox',
    '#title' => t("Group questions and answers"),
    '#default_value' => variable_get('faq_group_questions_top', FALSE),
    '#states' => array(
      'visible' => array(
        ':input[name="faq_category_display"]' => array(
          'value' => 'categories_inline',
        ),
        ':input[name="faq_display"]' => array(
          'value' => 'hide_qa',
        ),
      ),
    ),
  );
  $form['faq_category_misc']['faq_hide_child_terms'] = array(
    '#type' => 'checkbox',
    '#title' => t('Only show sub-categories when parent category is selected'),
    '#description' => t('This allows the user more control over how and when sub-categories are displayed.'),
    '#default_value' => variable_get('faq_hide_child_terms', FALSE),
    '#states' => array(
      'invisible' => array(
        ':input[name="faq_category_display"]' => array(
          'value' => 'categories_inline',
        ),
      ),
    ),
  );
  $form['faq_category_misc']['faq_show_term_page_children'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show sub-categories on FAQ category pages'),
    '#description' => t("Sub-categories with 'faq' nodes will be displayed on the per category FAQ page.  This will also happen if 'Only show sub-categories when parent category is selected' is set."),
    '#default_value' => variable_get('faq_show_term_page_children', FALSE),
    '#states' => array(
      'visible' => array(
        ':input[name="faq_hide_child_terms"]' => array(
          'checked' => FALSE,
        ),
        ':input[name="faq_category_display"]' => array(
          '!value' => 'categories_inline',
        ),
      ),
    ),
  );
  if (module_exists('taxonomy') && !empty($vocab_options)) {
    $form['faq_category_advanced'] = array(
      '#type' => 'fieldset',
      '#title' => t('Advanced category settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#states' => array(
        'visible' => array(
          ':input[name="faq_use_categories"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['faq_category_advanced']['faq_omit_vocabulary'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Omit vocabulary'),
      '#description' => t('Terms from these vocabularies will be <em>excluded</em> from the FAQ pages.'),
      '#default_value' => variable_get('faq_omit_vocabulary', array()),
      '#options' => $vocab_options,
      '#multiple' => TRUE,
    );
  }
  $form['#submit'][] = 'faq_categories_settings_form_submit';
  return system_settings_form($form);
}