You are here

function spaces_menu_items_validate in Spaces 7.3

Same name and namespace in other branches
  1. 6.3 spaces.module \spaces_menu_items_validate()
  2. 7 spaces.module \spaces_menu_items_validate()

Validate callback for spaces menu editor.

1 string reference to 'spaces_menu_items_validate'
spaces_get_menu_editor in ./spaces.module
@todo Please document this function.

File

./spaces.module, line 965

Code

function spaces_menu_items_validate($element, &$form_state) {
  $base_path = base_path();
  $items = array();
  $weight = -20;
  if (!empty($form_state['values']['space_menu_items'])) {
    foreach (json_decode($form_state['values']['space_menu_items']) as $i) {
      if (strpos($i, $base_path) === 0) {
        $path = substr($i, strlen($base_path));
        $path = array_shift(explode('#', $path));
        $path = drupal_get_normal_path($path);
        $path = empty($path) ? '<front>' : $path;
        $items[$path] = $weight;
        $weight++;
      }
    }
  }
  if (empty($items)) {
    form_set_error('space_menu_items', t('Invalid submission'));
  }
  else {
    $form_state['values']['space_menu_items'] = $items;
  }

  // Remove button values.
  unset($form_state['values']['edit']);
  unset($form_state['values']['cancel']);
}