You are here

function tmgmt_language_combination_field_validate in Translation Management Tool 7

Implements hook_field_validate().

File

translators/tmgmt_local/skills/tmgmt_language_combination.module, line 100

Code

function tmgmt_language_combination_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
  $existing = array();
  foreach ($items as $delta => $item) {
    $key = $item['language_from'] . ':' . $item['language_to'];
    if (!tmgmt_language_combination_field_is_empty($item, 'tmgmt_language_combination')) {
      if ($item['language_from'] == $item['language_to']) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'tmgmt_language_combination_equal',
          'message' => t("%name: The 'from' and 'to' language fields can't have the same value.", array(
            '%name' => $instance['label'],
          )),
        );
      }
      if (isset($existing[$key])) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'tmgmt_language_combination_equal',
          'message' => t('%name: The language combination has to be unique.', array(
            '%name' => $instance['label'],
          )),
        );
      }
    }
    $existing[$key] = TRUE;
  }
}