You are here

function menu_link_field_widget_validate in Menu Link (Field) 7

Form element validate handler for menu link field widget.

1 string reference to 'menu_link_field_widget_validate'
menu_link_field_widget_form in ./menu_link.field.inc
Implements hook_field_widget_form().

File

./menu_link.field.inc, line 629
Defines a menu link field type.

Code

function menu_link_field_widget_validate($element, &$form_state) {
  $item = drupal_array_get_nested_value($form_state['values'], $element['#parents']);
  if (!empty($item['parent']) && $item['parent'] != '_none') {
    list($item['menu_name'], $item['plid']) = explode(':', $item['parent']);
  }
  $item['link_title'] = trim($item['link_title']);
  if (!empty($item['description']) && trim($item['description'])) {
    $item['options']['attributes']['title'] = trim($item['description']);
  }
  else {

    // If the description field was left empty, remove the title attribute
    // from the menu link.
    unset($item['options']['attributes']['title']);
  }
  if (!empty($item['fragment']) && trim($item['fragment'])) {
    $item['options']['fragment'] = trim($item['fragment']);
  }
  else {
    unset($item['options']['fragment']);
  }
  form_set_value($element, $item, $form_state);
}