You are here

function safeword_field_validate in Safeword 7

Same name and namespace in other branches
  1. 8 safeword.module \safeword_field_validate()

Implements hook_field_validate().

Verifies that both the human and machine readable values are populated.

File

./safeword.module, line 136
Provides a FieldAPI field type, widget, and several formatters for a combined human readable/machine name pair of values. Possible uses include automatic generation of editable pathauto segments, handy Views argument values, and impressing friends.

Code

function safeword_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {

  // Set error message if non-Roman letters are found, suggest corrected machine name.
  if (function_exists('transliteration_get') && isset($field['settings']['transliterate']) && !empty($field['settings']['transliterate'])) {
    $machine_label = $field['settings']['machine_label'];
    foreach ($items as $delta => $item) {
      $machine_suggestion = transliteration_get($item['machine'], '-', 'en');
      $machine_suggestion = strtolower($machine_suggestion);
      if ($machine_suggestion != $item['machine']) {

        /*
         * @todo use regex pattern to strip out characters that would cause an error.
         */
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'safeword_invalid',
          'message' => t('The machine-readable name may only contain Roman characters, without accent, such as: %machine_suggestion', array(
            '%machine_suggestion' => $machine_suggestion,
          )),
        );
      }
    }
  }
  return;
}