You are here

function jump_menu_block_settings_submit in Better Jump Menus 7

Same name and namespace in other branches
  1. 8 jump_menu.module \jump_menu_block_settings_submit()

Submit handler to save block-specific jump menu settings. Keeps the variable clean and tidy!

1 string reference to 'jump_menu_block_settings_submit'
jump_menu_form_block_admin_configure_alter in ./jump_menu.module
Implements hook_form_FORM_ID_alter(). Add custom options to block editing forms.

File

./jump_menu.module, line 472
Make use of the CTools jump menu and grabs from an existing menu. See: modules/ctools/includes/jump-menu.inc NOTE: Menu items must be checked as "expanded" for traversing to work.

Code

function jump_menu_block_settings_submit($form, &$form_state) {
  $delta = $form_state['values']['delta'];
  $settings = variable_get('jump_menu_block_settings', array());
  $update_needed = FALSE;
  $system_defaults = array(
    'show_current' => JUMP_MENU_BLOCK_DEFAULTS_SHOW_CURRENT,
    'show_button' => JUMP_MENU_BLOCK_DEFAULTS_SHOW_BUTTON,
  );

  // Check all settings to clear out array if just default.
  foreach ($system_defaults as $config => $val) {

    // NOTE: Separated routes due to PHP notices with empty comparisons.
    // Also, every save shouldn't trigger a variable_set().
    // Config IS empty (new save).
    if (!isset($settings[$delta][$config])) {

      // Submission IS NOT default.
      if ($form_state['values']['jump_menu_' . $config] != $val) {
        $settings[$delta][$config] = $form_state['values']['jump_menu_' . $config];
        $update_needed = TRUE;
      }
      else {

        // Submission IS default, do nothing.
      }
    }
    else {

      // Submission DOES NOT match what was set previously.
      if ($form_state['values']['jump_menu_' . $config] != $settings[$delta][$config]) {
        $update_needed = TRUE;

        // Submission matches system default (set back to default).
        if ($form_state['values']['jump_menu_' . $config] == $val) {

          // Delete it to remove setting.
          unset($settings[$delta][$config]);
        }
        else {

          // Collect the new configuration.
          $settings[$delta][$config] = $form_state['values']['jump_menu_' . $config];
        }
      }
    }

    // No there is meaningful data for this block, but it's stored.
    if (isset($settings[$delta]) && count($settings[$delta]) == 0) {
      unset($settings[$delta]);
      $update_needed = TRUE;
    }
  }

  // Update the block settings variable if necessary.
  if ($update_needed) {
    variable_set('jump_menu_block_settings', $settings);
  }
}