You are here

function menu_position_add_rule in Menu Position 7

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

Adds a menu position rule.

Parameters

array $rule: An associate array defining the new rule to be created. Must contain the following keys:

  • admin_title: The administrative title of the rule.
  • conditions: An associative array whose keys are the machine names of the plugins actively configured in the rule. The value of each array element is array containing the necessary variables for that plugin.
  • menu_name: The machine name of the menu where this rule is positioned.
  • plid: The mlid of the parent menu link specified in the rule.

Return value

$rid ID of newly created rule.

1 call to menu_position_add_rule()
menu_position_rule_form_submit in ./menu_position.admin.inc
Handles form submission for menu_position_rule_form().

File

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

Code

function menu_position_add_rule(array $rule) {
  $fields = array(
    'admin_title' => $rule['admin_title'],
    'conditions' => serialize($rule['conditions']),
    'menu_name' => $rule['menu_name'],
    'plid' => $rule['plid'],
    'machine_name' => $rule['machine_name'],
  );
  $rid = db_insert('menu_position_rules')
    ->fields($fields)
    ->execute();
  $mlid = menu_position_add_menu_link($rid, $rule['plid'], $rule['admin_title']);

  // Now add the mlid back to the rule.
  db_update('menu_position_rules')
    ->fields(array(
    'mlid' => $mlid,
  ))
    ->condition('rid', $rid)
    ->execute();
  cache_clear_all('menu_position:rules:', 'cache', TRUE);
  return $rid;
}