You are here

function responsive_menus_admin_form in Responsive Menus 7

Admin settings form for which menus to responsify.

1 string reference to 'responsive_menus_admin_form'
responsive_menus_menu in ./responsive_menus.module
Implements hook_menu().

File

./responsive_menus.module, line 193
Responsify menus in Drupal.

Code

function responsive_menus_admin_form($form, &$form_state) {

  // Gather enabled styles.
  $styles = responsive_menus_styles();
  foreach ($styles as $style => $values) {
    $style_options[$style] = $values['name'];
  }

  // Get style settings form elements from ajax or the currently enabled style.
  if (!empty($form_state['values']['responsive_menus_style'])) {
    $current_style = $form_state['values']['responsive_menus_style'];
  }
  else {
    $current_style = variable_get('responsive_menus_style', 'responsive_menus_simple');
  }

  // Reminders about jQuery requirements if applicable.
  $form['responsive_menus_no_jquery_update'] = array(
    '#type' => 'checkboxes',
    '#description' => t("If the style you want requires newer jQuery version and you don't want to use jquery_update module."),
    '#options' => array(
      1 => t('I will provide my own jQuery library.'),
    ),
    '#default_value' => variable_get('responsive_menus_no_jquery_update', array(
      1 => 0,
    )),
  );

  // Ignore admin pages option.
  $form['responsive_menus_ignore_admin'] = array(
    '#type' => 'checkboxes',
    '#options' => array(
      1 => t('Ignore admin pages?'),
    ),
    '#default_value' => variable_get('responsive_menus_ignore_admin', array(
      1 => 1,
    )),
  );
  $jq_update_ignore = $form['responsive_menus_no_jquery_update']['#default_value'];
  $style_info = responsive_menus_style_load($current_style, $jq_update_ignore);
  $form['responsive_menus_style'] = array(
    '#type' => 'select',
    '#title' => t('Responsive menu style'),
    '#options' => $style_options,
    '#default_value' => $current_style,
    '#ajax' => array(
      'callback' => 'responsive_menus_style_settings_form',
      'wrapper' => 'rm-style-options',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );
  $form['responsive_menus_style_settings'] = array(
    '#title' => t('Style settings'),
    '#description' => t('Settings for chosen menu style.'),
    '#prefix' => '<div id="rm-style-options">',
    '#suffix' => '</div>',
    '#type' => 'fieldset',
    '#tree' => TRUE,
  );

  // Which selector to use info.
  if (!empty($style_info['selector'])) {
    $form['responsive_menus_style_settings']['selector_info'] = array(
      '#type' => 'item',
      '#title' => t('Selector(s) to use for this style:'),
      '#markup' => '<div class="messages status">' . $style_info['selector'] . '</div>',
    );
  }

  // Build additional style settings from style plugins.
  if (!empty($styles[$current_style]['form']) && function_exists($styles[$current_style]['form'])) {
    $styles_function = $styles[$current_style]['form'];
    foreach ($styles_function() as $name => $element) {
      $form['responsive_menus_style_settings'][$name] = $element;
    }
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  if (!empty($_POST) && form_get_errors()) {
    drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
  }
  $form['#submit'][] = 'responsive_menus_admin_form_submit';
  return $form;
}