You are here

function menu_position_rules_form_submit in Menu Position 7

Same name and namespace in other branches
  1. 6 menu_position.admin.inc \menu_position_rules_form_submit()
  2. 7.2 menu_position.admin.inc \menu_position_rules_form_submit()

Handles form submission for menu_position_rules_form().

File

./menu_position.admin.inc, line 251
Provides infrequently used functions and hooks for menu_position.

Code

function menu_position_rules_form_submit($form, &$form_state) {
  foreach ($form_state['values']['rules'] as $rid => $rule) {
    $fields = array(
      'enabled' => $rule['enabled'],
      'weight' => $rule['weight'],
    );
    $db_rule = db_query('SELECT * FROM {menu_position_rules} WHERE rid = :rid', array(
      ':rid' => $rid,
    ))
      ->fetchObject();
    if (!$rule['enabled']) {

      // If the rule has been disabled, remove the menu link.
      menu_link_delete($db_rule->mlid);
    }
    elseif (!$db_rule->enabled) {

      // If the rule has been enabled, add a menu link.
      $fields['mlid'] = menu_position_add_menu_link($rid, $db_rule->plid, $db_rule->admin_title);
    }
    db_update('menu_position_rules')
      ->fields($fields)
      ->condition('rid', $rid)
      ->execute();
  }
  cache_clear_all('menu_position:rules:', 'cache', TRUE);
  drupal_set_message(t('The new rules ordering has been applied.'));
}