You are here

function menu_position_enable in Menu Position 7.2

Same name and namespace in other branches
  1. 6 menu_position.install \menu_position_enable()
  2. 7 menu_position.install \menu_position_enable()

Implements hook_enable().

When the module is disabled, the menu links it owns are deleted. When re-enabling this module, we need to ensure that any menu links are re-created and to re-configure any old rules existing in the database.

File

./menu_position.install, line 111
Provides install, update and un-install functions for menu_position.

Code

function menu_position_enable() {
  $rules = db_query('SELECT rid, plid, admin_title FROM {menu_position_rules} WHERE enabled = :enabled', array(
    ':enabled' => 1,
  ));
  if ($rules
    ->rowCount()) {
    drupal_set_message(t('Existing menu position rules were discovered. They will be disabled until you visit the <a href="!url">menu position rules admin page</a>.', array(
      '!url' => url('admin/structure/menu-position'),
    )), 'error');
  }
  foreach ($rules as $rule) {

    // If we were to attempt menu_position_add_menu_link() here it would fail
    // because the module's router item isn't in the system yet. Instead we flag
    // the rule with a zero-value mlid and fix it in
    // menu_position_rules_form_callback().
    db_update('menu_position_rules')
      ->fields(array(
      'mlid' => 0,
    ))
      ->condition('rid', $rule->rid)
      ->execute();
  }
}