You are here

function video_widget_element_settings in Video 7

Same name and namespace in other branches
  1. 6.5 video_widget.inc \video_widget_element_settings()
  2. 6.4 video_widget.inc \video_widget_element_settings()

Process elements loads on settings

Parameters

<type> $element:

1 call to video_widget_element_settings()
video_field_widget_process in ./video.field.inc
An element #process callback for the image_image field type.

File

./video.module, line 275

Code

function video_widget_element_settings(&$element, &$form_state) {
  $file = $element['#value'];
  $delta = $element['#delta'];
  $field = field_widget_field($element, $form_state);
  $instance = field_widget_instance($element, $form_state);
  $settings = $instance['settings'];

  // Check if using the default width and replace tokens.
  $default_dimensions = user_access('override player dimensions');
  $description = t('Set your video dimensions.  This will create your player with these dimensions.');

  //setup our default dimensions.
  $dimensions = $settings['default_dimensions'];
  $player_dimensions = $settings['default_player_dimensions'];

  // Lets figure out our dimensions for our video and add astericks next to our options.
  $options = video_explode("\n", variable_get("video_metadata_dimensions", video_default_dimensions()));
  if ($field['settings']['autoconversion'] && isset($element['preview']) && $file['fid'] != 0 && $default_dimensions) {
    $file_object = file_load($file['fid']);
    $video_info = _video_dimensions_options($options, drupal_realpath($file_object->uri));
    $description = t('Set your video dimensions.  This will create your player
      and transcode your video with these dimensions.  Your video size is !size,
      if you choose a higher resolution, this could cause video distortion.
      You are shown dimensions that match your aspect ratio,
      if you choose dimensions that do not match your ratio, we will pad your
      video by adding black bars on either the top or bottom while maintaining
      your videos original aspect ratio.', array(
      '!size' => $video_info['width'] . 'x' . $video_info['height'],
    ));

    //setup our default display of dimensions.

    //lets go through our options looking for a matching resolution
    foreach ($options as $key => $value) {
      if (stristr($value, t('(Matches Resolution)')) == TRUE) {
        $dimensions = $key;
        break;
      }
    }
  }

  // Override our dimensions to the user selected.
  if (isset($file['dimensions']) && !empty($file['dimensions'])) {
    $dimensions = $file['dimensions'];
  }

  // Override our player dimensions to the user selected.
  if (isset($file['player_dimensions']) && !empty($file['player_dimensions'])) {
    $player_dimensions = $file['player_dimensions'];
  }

  // show only enabled the autoconversion
  if ($field['settings']['autoconversion']) {
    $element['dimensions'] = array(
      '#type' => 'select',
      '#title' => t('Dimensions for Video Transcoding'),
      '#default_value' => $dimensions,
      '#description' => $description,
      '#options' => $options,
    );
  }

  // get the player dimentions
  $element['player_dimensions'] = array(
    '#type' => 'select',
    '#title' => t('Dimensions for Video Player'),
    '#default_value' => $player_dimensions,
    '#description' => t('WxH of your video player.'),
    '#options' => $options,
  );

  // If users cannot change the default dimensions, lets change this to a value.
  if (!$default_dimensions) {
    $element['dimensions']['#type'] = 'value';
    $element['dimensions']['#value'] = $dimensions;
    $element['player_dimensions']['#type'] = 'value';
    $element['player_dimensions']['#value'] = $player_dimensions;
  }

  // only in preview mode and then create thumbnails
  if ($field['settings']['autoconversion']) {

    // check if already converted or failed
    module_load_include('inc', 'video', '/includes/conversion');
    $video_conversion = new video_conversion();
    $video = $video_conversion
      ->load_job($file['fid']);
    if (user_access('re convert video') && isset($video->video_status) && ($video->video_status == VIDEO_RENDERING_COMPLETE || $video->video_status == VIDEO_RENDERING_FAILED)) {
      $status = array(
        VIDEO_RENDERING_COMPLETE => 'completed',
        VIDEO_RENDERING_FAILED => 'failed',
      );
      $element['re_convert_video'] = array(
        '#type' => 'checkbox',
        '#title' => t('Video conversion has been <b>' . $status[$video->video_status] . '!</b>. Re-queue video?.'),
        '#description' => t('This will re-convert your video to output formats when you save, or scheduling it for cron.'),
        '#attributes' => array(
          'class' => array(
            'video-re-convert',
            'video-' . $video->video_status,
          ),
        ),
      );
    }
    if (user_access('bypass conversion video')) {
      $element['bypass_autoconversion'] = array(
        '#type' => 'checkbox',
        '#title' => t('Bypass auto conversion'),
        '#default_value' => isset($file['bypass_autoconversion']) ? $file['bypass_autoconversion'] : variable_get('video_bypass_conversion', FALSE),
        '#description' => t('This will bypass your auto conversion of videos.'),
        '#attributes' => array(
          'class' => array(
            'video-bypass-auto-conversion',
          ),
        ),
      );
    }
    elseif (variable_get('video_bypass_conversion', FALSE)) {
      $element['bypass_autoconversion'] = array(
        '#type' => 'value',
        '#value' => variable_get('video_bypass_conversion', FALSE),
      );
    }

    // check this to convert the video on save
    $convert = isset($file['convert_video_on_save']) ? $file['convert_video_on_save'] : variable_get('video_convert_on_save', FALSE);
    if (user_access('convert on submission')) {
      $element['convert_video_on_save'] = array(
        '#type' => 'checkbox',
        '#title' => t('Convert video on save'),
        '#default_value' => $convert,
        '#description' => t('This will convert your video to flv format when you save, instead of scheduling it for cron.'),
        '#attributes' => array(
          'class' => array(
            'video-convert-video-on-save',
          ),
        ),
      );
    }
    elseif (variable_get('video_convert_on_save', FALSE)) {
      $element['convert_video_on_save'] = array(
        '#type' => 'value',
        '#value' => variable_get('video_convert_on_save', FALSE),
      );
    }
  }

  // use of default thumbnail
  $default_thumb = isset($file['use_default_video_thumb']) ? $file['use_default_video_thumb'] : variable_get('video_use_default_thumb', FALSE);
  if (user_access('use default thumb')) {
    $element['use_default_video_thumb'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use the default thumbnail for this video?'),
      '#default_value' => $default_thumb,
      '#description' => t('This will set a flag for this video to use the default video thumbnail when outputed..'),
      '#attributes' => array(
        'class' => array(
          'video-use-default-video-thumb',
        ),
      ),
    );
    if ($default_thumb) {
      $element['use_default_video_thumb']['#attributes']['checked'] = 'checked';
    }
  }
  else {
    $element['use_default_video_thumb'] = array(
      '#type' => 'value',
      '#value' => $default_thumb,
    );
  }
}