You are here

function groupmenu_node_form_validate in Group Menu 7

Validation handler for Group node forms.

We will only end up here if we have confirmed that the node is a group type content.

1 string reference to 'groupmenu_node_form_validate'
groupmenu_form_node_form_alter in ./groupmenu.module
Implements hook_form_FORMID_alter().

File

./groupmenu.module, line 488
Integrates menu with Group.

Code

function groupmenu_node_form_validate($form, &$form_state) {

  // If the user didn't ask for a menu, we have nothing to do.
  if (!isset($form_state['values']['menu']['enabled']) || $form_state['values']['menu']['enabled'] !== 1) {
    return;
  }

  // Available menus were discovered in groupmenu_node_prepare().
  $menus = $form['#node']->storage['groupmenu'];
  $parents = explode(':', $form_state['values']['menu']['parent']);
  $parent = $parents[0];
  $has_menu_access = FALSE;
  $gids = _groupmenu_get_user_group_ids();
  foreach ($menus as $menu) {
    if ($menu['menu_name'] == $parent) {

      // Check if user has access to the chosen menu parent.
      $has_menu_access = TRUE;

      // Check if menu belongs to one of the selected groups.
      if (!in_array($menu['gid'], $gids)) {
        form_set_error('group_groups', t('The menu you chose does not belong to the selected groups.'));
      }
    }
  }
  if (!$has_menu_access) {
    form_set_error('menu][parent', t('You cannot add menu items to this menu. Choose another parent menu.'));
  }
}