You are here

function video_field_widget_form in Video 7.2

Same name and namespace in other branches
  1. 7 video.field.inc \video_field_widget_form()

Implements hook_field_widget_form().

File

./video.field.inc, line 628
Implement a video field, based on the file module's file field.

Code

function video_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {

  // Add display_field setting to field because file_field_widget_form() assumes it is set.
  $field['settings']['display_field'] = 0;
  if (module_exists('filefield_role_limit')) {
    filefield_role_limit_file_field_process($element, $form_state, $form);
  }
  $elements = file_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  $settings = $instance['settings'];
  foreach (element_children($elements) as $delta) {

    // If not using custom extension validation, ensure this is an video.
    $supported_extensions = video_utility::getMediaExtensions();
    $extensions = isset($elements[$delta]['#upload_validators']['file_validate_extensions'][0]) ? $elements[$delta]['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions);
    $extensions = array_intersect(explode(' ', $extensions), $supported_extensions);
    $elements[$delta]['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions);

    // Add all extra functionality provided by the video widget.
    $elements[$delta]['#process'][] = 'video_field_widget_process';

    // Add thumbnail stub to prevent errors in file_ajax_upload().
    $elements[$delta]['thumbnail'] = array(
      '#type' => 'value',
      '#value' => NULL,
    );

    // Override value loader
    $elements[$delta]['#value_callback'] = 'video_field_widget_value';
  }
  if ($field['cardinality'] == 1) {

    // If there's only one field, return it as delta 0.
    if (empty($elements[0]['#default_value']['fid'])) {
      $elements[0]['#description'] = theme('file_upload_help', array(
        'description' => $instance['description'],
        'upload_validators' => $elements[0]['#upload_validators'],
      ));
    }
  }
  else {
    $elements['#file_upload_description'] = theme('file_upload_help', array(
      'upload_validators' => $elements[0]['#upload_validators'],
    ));
  }
  return $elements;
}