You are here

function video_widget_element_settings in Video 6.5

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

Process elements loads on settings

2 calls to video_widget_element_settings()
uploadfield_widget_process in types/uploadfield/uploadfield_widget.inc
Element #process callback function.
videoftp_widget_process in types/videoftp/videoftp_widget.inc
Process an individual element.

File

./video_widget.inc, line 10
Common Video module widget functions

Code

function video_widget_element_settings(&$element) {
  $file = $element['#value'];
  $delta = $element['#delta'];
  $field = content_fields($element['#field_name'], $element['#type_name']);

  // Check if using the default width and replace tokens.
  $override_dimensions = user_access('override player dimensions');
  $allow_autoconversion = !empty($field['widget']['autoconversion']);

  // Setup our default dimensions.
  $dimensions = $field['widget']['default_dimensions'];
  $player_dimensions = $field['widget']['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_dimensions', video_default_dimensions()));
  if (isset($element['preview']) && $override_dimensions) {
    if ($allow_autoconversion) {
      $video_info = _video_dimensions_options($options, $file['filepath']);
      $description = t('Set your video dimensions. This will ctranscode your video with these dimensions.');
      if (!empty($video_info)) {
        $description .= t('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'],
        ));
        $dimensions = $video_info['width'] . 'x' . $video_info['height'];
      }

      // Override our dimensions to the user selected.
      if (!empty($file['data']['dimensions'])) {
        $dimensions = $file['data']['dimensions'];
      }
      $element['data']['dimensions'] = array(
        '#type' => 'select',
        '#title' => t('Dimensions transcoding'),
        '#default_value' => $dimensions,
        '#description' => $description,
        '#options' => $options,
      );
    }
    else {
      $element['noautoconvert'] = array(
        '#type' => 'markup',
        '#value' => '<p><small>' . t('This video will not be transcoded because the setting @setting-name is off for this field.', array(
          '@setting-name' => t('Enable video conversion'),
        )) . '</small></p>',
        '#weight' => 50,
      );
    }
  }
  if ($override_dimensions) {

    // Override our player dimensions to the user selected.
    if (!empty($file['data']['player_dimensions'])) {
      $player_dimensions = $file['data']['player_dimensions'];
    }
    $element['data']['player_dimensions'] = array(
      '#type' => 'select',
      '#title' => t('Dimensions for video player'),
      '#default_value' => $player_dimensions,
      '#description' => t('WxH of your video player.'),
      '#options' => $options,
    );
  }

  // only in preview mode and then create thumbnails
  if ($allow_autoconversion) {
    $bypass = isset($file['data']['bypass_autoconversion']) ? $file['data']['bypass_autoconversion'] : variable_get('video_bypass_conversion', FALSE);
    if (user_access('bypass conversion video')) {
      $element['data']['bypass_autoconversion'] = array(
        '#type' => 'checkbox',
        '#title' => t('Bypass auto conversion'),
        '#default_value' => $bypass,
        '#description' => t('This will bypass your auto conversion of videos.'),
        '#attributes' => array(
          'class' => 'video-bypass-auto-conversion',
        ),
      );
      if ($file['status'] == FILE_STATUS_TEMPORARY) {

        // Checkbox #default_value does not work when the checkbox is inserted using AHAH
        $element['data']['bypass_autoconversion']['#value'] = $bypass;
      }
    }
    else {
      $element['data']['bypass_autoconversion'] = array(
        '#type' => 'value',
        '#value' => $bypass,
      );
    }
    $convert = isset($file['data']['convert_video_on_save']) ? $file['data']['convert_video_on_save'] : variable_get('video_convert_on_save', FALSE);
    if (user_access('convert on submission')) {
      $element['data']['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' => 'video-convert-video-on-save',
        ),
      );
      if ($file['status'] == FILE_STATUS_TEMPORARY) {

        // Checkbox #default_value does not work when the checkbox is inserted using AHAH
        $element['data']['convert_video_on_save']['#value'] = $convert;
      }
    }
    else {
      $element['data']['convert_video_on_save'] = array(
        '#type' => 'value',
        '#value' => $convert,
      );
    }
    $default_thumb = isset($file['data']['use_default_video_thumb']) ? $file['data']['use_default_video_thumb'] : variable_get('video_use_default_thumb', FALSE);
    if (user_access('use default thumb')) {
      $element['data']['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' => 'video-use-default-video-thumb',
        ),
      );
      if ($file['status'] == FILE_STATUS_TEMPORARY) {

        // Checkbox #default_value does not work when the checkbox is inserted using AHAH
        $element['data']['use_default_video_thumb']['#value'] = $default_thumb;
      }
    }
    else {
      $element['data']['use_default_video_thumb'] = array(
        '#type' => 'value',
        '#value' => $default_thumb,
      );
    }
  }
}