You are here

function soundcloudfield_field in SoundCloud field 6

Implementation of hook_field().

File

./soundcloudfield.module, line 89
SoundCloud CCK field.

Code

function soundcloudfield_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    case 'validate':
      if (is_array($items)) {
        foreach ($items as $delta => $item) {
          $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
          if (is_array($item) && isset($item['_error_element'])) {
            unset($item['_error_element']);
          }
          if (!empty($item['embed']) && !preg_match('@^https?://soundcloud\\.com/([^"\\&]+)@i', $item['embed'], $matches)) {
            form_set_error($field['field_name'], t('"%url" is not a valid SoundCloud URL', array(
              '%url' => $item['embed'],
            )));
          }
        }
      }
      break;
    case 'sanitize':
      foreach ($items as $delta => $item) {
        $items[$delta]['safe'] = check_plain($item['embed']);
      }
      break;
  }
}