You are here

function image_attach_form_alter in Image 5.2

Same name and namespace in other branches
  1. 5 contrib/image_attach/image_attach.module \image_attach_form_alter()
  2. 6 contrib/image_attach/image_attach.module \image_attach_form_alter()

implementation of hook_form_alter()

File

contrib/image_attach/image_attach.module, line 124
image_attach.module

Code

function image_attach_form_alter($form_id, &$form) {

  // Content type settings form.
  if ($form_id == 'node_type_form' && $form['#node_type']->type != 'image') {
    _image_check_settings();
    $image_sizes = array(
      IMAGE_ATTACH_HIDDEN => t('<Hidden>'),
    );
    foreach (image_get_sizes() as $key => $size) {
      $image_sizes[$key] = $size['label'];
    }
    $form['workflow']['image_attach'] = array(
      '#type' => 'fieldset',
      '#title' => t('Image Attach settings'),
      '#collapsible' => FALSE,
    );
    $form['workflow']['image_attach']['image_attach'] = array(
      '#type' => 'radios',
      '#title' => t('Attach Images'),
      '#default_value' => variable_get('image_attach_' . $form['#node_type']->type, 0),
      '#options' => array(
        0 => t('Disabled'),
        1 => t('Enabled'),
      ),
      '#description' => t('Should this node allows users to upload an image?'),
    );
    $form['workflow']['image_attach']['image_attach_size_teaser'] = array(
      '#type' => 'select',
      '#title' => t('Teaser image size'),
      '#default_value' => variable_get('image_attach_size_teaser_' . $form['#node_type']->type, IMAGE_THUMBNAIL),
      '#options' => $image_sizes,
      '#description' => t("This determines the size of the image that appears when the node is displayed as a teaser. 'Hidden' will not show the image."),
    );
    $form['workflow']['image_attach']['image_attach_weight_teaser'] = array(
      '#type' => 'weight',
      '#title' => t('Teaser image weight'),
      '#default_value' => variable_get('image_attach_weight_teaser_' . $form['#node_type']->type, 0),
      '#description' => t("This value determines the order of the image when displayed in the teaser."),
    );
    $form['workflow']['image_attach']['image_attach_size_body'] = array(
      '#type' => 'select',
      '#title' => t('Full node image size'),
      '#default_value' => variable_get('image_attach_size_body_' . $form['#node_type']->type, IMAGE_THUMBNAIL),
      '#options' => $image_sizes,
      '#description' => t("This determines the size of the image that appears when the full node is displayed. 'Hidden' will not show the image."),
    );
    $form['workflow']['image_attach']['image_attach_weight_body'] = array(
      '#type' => 'weight',
      '#title' => t('Full node image weight'),
      '#default_value' => variable_get('image_attach_weight_body_' . $form['#node_type']->type, 0),
      '#description' => t("This value determines the order of the image when displayed in the body."),
    );
  }
  else {
    if (isset($form['type']) && $form['type']['#value'] != 'image') {
      $type = $form['type']['#value'];

      // If enabled adjust the form.
      if ($form_id == $type . '_node_form' && variable_get('image_attach_' . $type, 0)) {
        $node = $form['#node'];
        _image_check_settings();
        $value = $node->new_image ? '#value' : '#default_value';
        $form['#attributes'] = array(
          "enctype" => "multipart/form-data",
        );
        $form['image_attach'] = array(
          '#type' => 'fieldset',
          '#title' => t('Attached Images'),
          '#collapsible' => TRUE,
          '#collapsed' => !$node->iid,
        );
        if ($node->iid) {
          $image = node_load($node->iid);
          $form['image_attach']['image_thumbnail'] = array(
            '#type' => 'item',
            '#title' => t('Thumbnail'),
            '#value' => image_display($image, 'thumbnail'),
          );
        }
        if (variable_get('image_attach_existing', 1) && user_access('access content')) {
          $form['image_attach']['iid'] = array(
            '#type' => 'select',
            '#title' => t('Existing Image'),
            '#options' => _image_attach_get_image_nodes(),
            $value => $node->iid,
            '#description' => t('Choose an image already existing on the server if you do not upload a new one.'),
          );
          $form['image_attach'][] = array(
            '#type' => 'item',
            '#value' => t('-or-'),
            '#attributes' => array(
              'class' => 'either-choice',
            ),
          );
        }
        else {
          $form['image_attach']['iid'] = array(
            '#type' => 'hidden',
            $value => $node->iid,
          );
        }
        $form['image_attach']['image'] = array(
          '#type' => 'file',
          '#title' => t('Upload Image'),
        );
        $form['image_attach']['image_title'] = array(
          '#type' => 'textfield',
          '#title' => t('Image title'),
          $value => '',
          '#description' => t('The title the image will be shown with.'),
        );
      }
    }
  }
}