You are here

function video_image_form_alter in Video 5

Same name and namespace in other branches
  1. 6 plugins/video_image/video_image.module \video_image_form_alter()
  2. 6.2 plugins/video_image/video_image.module \video_image_form_alter()

Implementation of hook_form_alter()

File

plugins/video_image/video_image.module, line 132
Enable image support for video module.

Code

function video_image_form_alter($form_id, &$form) {
  if ($form_id == 'video_node_form') {
    $node = $form['#node'];
    $value = $node->new_image ? '#value' : '#default_value';
    $form['iid'] = array(
      '#type' => 'hidden',
      $value => $node->iid,
    );
    if (!is_array($node->tempimage['fids'])) {
      $fids = array(
        '_original' => 0,
      );
      foreach (_image_get_sizes() as $size) {
        $fids[$size['label']] = 0;
      }
      $node->tempimage['fids'] = $fids;
    }
    $form['tempimage']['#tree'] = true;
    foreach ($node->tempimage['fids'] as $label => $fid) {
      $form['tempimage']['fids'][$label] = array(
        '#type' => 'hidden',
        $value => $fid,
      );
    }
    $auto_thumbable = video_image_is_autothumbable($node);
    if (!$auto_thumbable || user_access('override autothumnailing using uploaded images')) {

      // let's be sure that image directories are ready
      if (function_exists('_image_check_settings')) {
        _image_check_settings();
      }

      // needed for uploading
      $form['#attributes'] = array(
        "enctype" => "multipart/form-data",
      );
      $form['image'] = array(
        '#type' => 'fieldset',
        '#title' => t('Image thumbnails'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#weight' => -17,
        '#description' => t('Upload an image to be used as the thumbnail for this video.'),
      );
      $form['image']['image'] = array(
        '#type' => 'file',
        '#title' => t('Image'),
      );
    }
    if ($node->nid && $auto_thumbable) {
      $form['regenerate_thumbnail'] = array(
        '#type' => 'checkbox',
        '#title' => t('Auto regenerate thumbnail'),
        '#default_value' => 0,
      );
    }
  }
}