You are here

function og_menu_form_alter in Organic Groups Menu (OG Menu) 7.3

Same name and namespace in other branches
  1. 8 og_menu.module \og_menu_form_alter()
  2. 5 og_menu.module \og_menu_form_alter()
  3. 6.2 og_menu.module \og_menu_form_alter()
  4. 6 og_menu.module \og_menu_form_alter()
  5. 7.2 og_menu.module \og_menu_form_alter()

Implements hook_form_FORMID_alter().

Integration with Menu Position module for menu_position config page. Hides OG Menus from available parent options settings.

File

./og_menu.module, line 605
Integrates Menu with Organic Groups. Lots of menu forms duplication in OG context.

Code

function og_menu_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'menu_position_add_rule_form' || $form_id == 'menu_position_edit_rule_form') {
    if (!variable_get('og_menu_show_menuposition', FALSE)) {
      $mlid = !empty($form_state['#menu-position-rule']['mlid']) ? $form_state['#menu-position-rule']['mlid'] : NULL;
      $menus = menu_get_menus();

      // @todo convert to new database api functions
      $result = db_query("SELECT mc.menu_name FROM {menu_custom} mc, {og_menu} ogm WHERE ogm.menu_name = mc.menu_name")
        ->fetchCol();
      foreach ($result as $ogblock) {
        unset($menus[$ogblock]);
      }

      // Parent menu item.
      if ($mlid) {
        $options = menu_parent_options($menus, menu_link_load($mlid));
      }
      else {
        $options = menu_parent_options($menus, array(
          'mlid' => 0,
        ));
      }
      $form['plid']['#options'] = $options;
    }
  }
}