You are here

function video_form in Video 6

Same name and namespace in other branches
  1. 5 video.module \video_form()
  2. 6.2 video.module \video_form()

Hook, displays the contents of the node form page for creating and editing nodes.

Parameters

$node: object

Return value

string value of form content

File

./video.module, line 594
video.module

Code

function video_form($node) {

  //We must unserialize the array for display in the forms.
  if ($node->serial_data) {
    $node->serial_data = unserialize($node->serialized_data);
  }
  $form = array();

  // default node stuff
  $type = node_get_types('type', $node);
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#size' => 60,
    '#maxlength' => 128,
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#weight' => -20,
  );
  if ($type->has_body) {
    $form['body_filter']['body'] = array(
      '#type' => 'textarea',
      '#title' => check_plain($type->body_label),
      '#required' => $type->min_word_count > 0,
      '#rows' => 10,
      '#default_value' => $node->body,
    );
    $form['body_filter']['format'] = filter_form($node->format);
  }

  // set an hidden field to store video type
  $form['vtype'] = array(
    '#type' => 'hidden',
    '#value' => $node->vtype,
  );
  $form['video'] = array(
    '#type' => 'fieldset',
    '#title' => t('Video Information'),
    '#weight' => -19,
  );
  if (!video_support_autoresolution($node)) {

    // this vtype doesn't support autoresolution
    // let's display the resolution selection
    $form['video']['vresolution'] = array(
      '#type' => 'select',
      '#title' => t('Resolution'),
      '#description' => t("Select the approriate resolution (aspect ratio) for your video.<br />If you don't know what to choose then the default value will probably be ok for you."),
      '#options' => _video_get_resolution_options(),
      '#default_value' => _video_get_resolution_selected_option($node),
      '#required' => true,
    );
  }
  else {

    // set an hidden field to store video resolution
    $form['hvresolution'] = array(
      '#type' => 'hidden',
      '#value' => $node->videox . 'x' . $node->videoy,
    );
  }
  if (!video_support_autoplaytime($node)) {

    // this vtype doesn't support autoplaytime
    $form['video']['playtime'] = array(
      '#type' => 'fieldset',
      '#title' => t('Playtime'),
      '#collapsible' => true,
      '#collapsed' => $node->playtime_seconds ? false : true,
      // display expanded if we have values inserted by the user
      '#description' => t('Insert here the duration of the video.<br />Values may be entered in excess of their normal "clock maximum" (the seconds field may be 3600 to represent 1 hour), however each value will be summed for a total of all three.'),
    );
    $playtime = _video_sec2hms($node->playtime_seconds);
    $form['video']['playtime']['playtime_hours'] = array(
      '#type' => 'textfield',
      '#title' => t('Hours'),
      '#size' => 11,
      '#maxlength' => 11,
      '#default_value' => $playtime['hours'],
    );
    $form['video']['playtime']['playtime_minutes'] = array(
      '#type' => 'textfield',
      '#title' => t('Minutes'),
      '#size' => 11,
      '#maxlength' => 11,
      '#default_value' => $playtime['minutes'],
    );
    $form['video']['playtime']['playtime_seconds'] = array(
      '#type' => 'textfield',
      '#title' => t('Seconds'),
      '#required' => FALSE,
      '#size' => 11,
      '#maxlength' => 11,
      '#default_value' => $playtime['seconds'],
    );
  }
  else {

    // set an hidden field to store video length
    $form['playtime_seconds'] = array(
      '#type' => 'hidden',
      '#value' => $node->playtime_seconds,
    );

    // we need to store file size too
    $form['hsize'] = array(
      '#type' => 'hidden',
      '#value' => $node->size,
    );
  }

  // Get the video-type-specific bits.
  $form = module_invoke('video_' . $node->vtype, 'v_form', $node, $form);
  return $form;
}