You are here

function menu_editor_validate_item in Menu Editor 7

Same name and namespace in other branches
  1. 6.3 menu_editor.admin.inc \menu_editor_validate_item()
  2. 6 menu_editor.admin.inc \menu_editor_validate_item()
  3. 6.2 menu_editor.admin.inc \menu_editor_validate_item()

Validate form values for a menu link being added or edited.

Parameters

array $element:

string $link_path:

string $error_key_prefix:

1 call to menu_editor_validate_item()
menu_editor_overview_form_validate in ./menu_editor.admin.inc
Form validation callback for menu_editor_overview_form.

File

./menu_editor.admin.inc, line 409

Code

function menu_editor_validate_item(array &$element, $link_path, $error_key_prefix) {
  $placeholders = menu_editor_get_placeholders();
  if (isset($placeholders[$link_path])) {

    // it would be hard to check access,
    // because we don't necessarily know the mlid.
    // Thus, we simply grant access for all placeholders.
    return;
  }
  if ($element['link_path']['#default_value'] === $link_path) {

    // link_path is the only field that we check,
    // and we don't complain about existing link paths.
    return;
  }
  $item = $element['#item'];
  $normal_path = drupal_get_normal_path($link_path);
  $item['link_path'] = $normal_path;
  if (!url_is_external($normal_path)) {
    $parsed_link = parse_url($normal_path);
    if (isset($parsed_link['query'])) {
      $item['options']['query'] = drupal_get_query_array($parsed_link['query']);
    }
    if (isset($parsed_link['fragment'])) {
      $item['options']['fragment'] = $parsed_link['fragment'];
    }
    $item['link_path'] = $parsed_link['path'];
  }
  if (!trim($item['link_path']) || !drupal_valid_path($item['link_path'])) {
    form_set_error($error_key_prefix . 'link_path', t("The path '@link_path' is either invalid or you do not have access to it.", array(
      '@link_path' => $item['link_path'],
    )));
  }
}