You are here

function entity_translation_i18n_menu_form_menu_edit_item_validate in Entity Translation 7

Validation handler for the menu item edit form.

1 string reference to 'entity_translation_i18n_menu_form_menu_edit_item_validate'
entity_translation_i18n_menu_form_menu_edit_item_alter in entity_translation_i18n_menu/entity_translation_i18n_menu.module
Implements hook_form_FORM_ID_alter().

File

entity_translation_i18n_menu/entity_translation_i18n_menu.module, line 195
The menu specific translation functions and hook implementations.

Code

function entity_translation_i18n_menu_form_menu_edit_item_validate($form, &$form_state) {
  $item = $form_state['values'];

  // Localizable menu items should not be created when a translation set for the
  // same path already exists (exluding special paths starting by <).
  if ($item['language'] == LANGUAGE_NONE && strpos($item['link_path'], '<') !== 0) {
    $count = db_select('menu_links', 'ml')
      ->condition('ml.link_path', $item['link_path'])
      ->condition('ml.i18n_tsid', 0, '<>')
      ->countQuery()
      ->execute()
      ->fetchField();
    if (!empty($count)) {
      form_set_error('language', t('There are already one or more items with a language assigned for the given path. Remove them or assign a language to this item too.'));
    }
  }
}