public function MenuLinkFormController::validate

Overrides EntityFormController::validate().

Overrides EntityFormController::validate

File

drupal/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php, line 183
Contains \Drupal\menu_link\MenuLinkFormController.

Class

MenuLinkFormController
Form controller for the node edit forms.

Namespace

Drupal\menu_link

Code

public function validate(array $form, array &$form_state) {
  $menu_link = $this
    ->buildEntity($form, $form_state);
  $normal_path = $this->pathAliasManager
    ->getSystemPath($menu_link->link_path);
  if ($menu_link->link_path != $normal_path) {
    drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array(
      '%link_path' => $menu_link->link_path,
      '%normal_path' => $normal_path,
    )));
    $menu_link->link_path = $normal_path;
  }
  if (!url_is_external($menu_link->link_path)) {
    $parsed_link = parse_url($menu_link->link_path);
    if (isset($parsed_link['query'])) {
      $menu_link->options['query'] = drupal_get_query_array($parsed_link['query']);
    }
    else {

      // Use unset() rather than setting to empty string
      // to avoid redundant serialized data being stored.
      unset($menu_link->options['query']);
    }
    if (isset($parsed_link['fragment'])) {
      $menu_link->options['fragment'] = $parsed_link['fragment'];
    }
    else {
      unset($menu_link->options['fragment']);
    }
    if (isset($parsed_link['path']) && $menu_link->link_path != $parsed_link['path']) {
      $menu_link->link_path = $parsed_link['path'];
    }
  }
  if (!trim($menu_link->link_path) || !drupal_valid_path($menu_link->link_path, TRUE)) {
    form_set_error('link_path', t("The path '@link_path' is either invalid or you do not have access to it.", array(
      '@link_path' => $menu_link->link_path,
    )));
  }
  parent::validate($form, $form_state);
}