You are here

function soundcloudfield_field_validate in SoundCloud field 7

Implements hook_field_validate().

Pseudo-hook.

File

./soundcloudfield.module, line 46
@author Attila Fekete - http://drupal.org/user/762986

Code

function soundcloudfield_field_validate($entity_type, $entity, $field, $instance, $langcode, &$items, &$errors) {
  if ($field['type'] == 'soundcloud') {
    foreach ($items as $delta => $item) {
      if (!empty($item['url']) && !preg_match('@^https?://soundcloud\\.com/([^"\\&]+)@i', $item['url'], $matches)) {
        $errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => 'soundcloudfield_invalid_url',
          'message' => t('%url is not a valid SoundCloud URL.', array(
            '%url' => $item['url'],
          )),
        );
      }
    }
  }
}