You are here

function youtube_field_widget_form in YouTube Field 7

Implements hook_field_widget_form().

File

./youtube.module, line 602

Code

function youtube_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $value = isset($items[$delta]['input']) ? $items[$delta]['input'] : '';
  $element['input'] = $element + array(
    '#type' => 'textfield',
    '#default_value' => $value,
    '#size' => 60,
    '#maxlength' => 1024,
    '#element_validate' => array(
      'youtube_input_validate',
    ),
  );

  // Add our own description if one is not provided by the UI.
  if ($element['#description'] == '') {
    $element['input']['#description'] = t('Enter the YouTube URL. Valid URL
      formats include: http://www.youtube.com/watch?v=1SqBdS0XkV4 and
      http://youtu.be/1SqBdS0XkV4');
  }
  if (isset($items[$delta]['video_id'])) {
    $element['video_id'] = array(
      '#prefix' => '<div class="youtube-video-id">',
      '#markup' => t('YouTube video ID: !video_id', array(
        '!video_id' => $items[$delta]['video_id'],
      )),
      '#suffix' => '</div>',
      '#weight' => 1,
    );
  }
  return $element;
}