You are here

function image_form in Image 6

Same name and namespace in other branches
  1. 5.2 image.module \image_form()
  2. 5 image.module \image_form()

Implementation of hook_form().

File

./image.module, line 308

Code

function image_form(&$node, $form_state) {
  _image_check_settings();
  if (!$_POST && !empty($_SESSION['image_upload'])) {
    unset($_SESSION['image_upload']);
  }
  $type = node_get_types('type', $node);
  $form['#validate'][] = 'image_form_validate';
  $form['#submit'][] = 'image_form_submit';
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#size' => 60,
    '#maxlength' => 128,
    '#required' => TRUE,
    '#default_value' => $node->title,
  );
  $form['images']['#tree'] = TRUE;
  foreach (image_get_sizes() as $key => $size) {
    $form['images'][$key] = array(
      '#type' => 'value',
      '#value' => isset($node->images[$key]) ? $node->images[$key] : '',
    );
  }
  $form['new_file'] = array(
    '#type' => 'value',
    '#default_value' => isset($node->new_file) ? $node->new_file : FALSE,
  );
  $form['#attributes'] = array(
    'enctype' => 'multipart/form-data',
  );
  $form['image'] = array(
    '#prefix' => '<div class="image-field-wrapper">',
    '#suffix' => '</div>',
  );
  $form['image']['thumbnail'] = array(
    '#type' => 'item',
    '#after_build' => array(
      'image_form_add_thumbnail',
    ),
  );
  $form['image']['image'] = array(
    '#type' => 'file',
    '#title' => t('Image'),
    '#size' => 40,
    '#description' => t('Select an image to upload.'),
  );
  $form['image']['rebuild_images'] = array(
    '#type' => 'checkbox',
    '#title' => t('Rebuild derivative images'),
    '#default_value' => FALSE,
    '#description' => t('Check this to rebuild the derivative images for this node.'),
    '#access' => !isset($node->nid) ? FALSE : TRUE,
  );
  if ($type->has_body) {
    $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
  }
  return $form;
}