You are here

function node_gallery_config_form in Node Gallery 6.2

Same name and namespace in other branches
  1. 6 node_gallery.admin.inc \node_gallery_config_form()
2 string references to 'node_gallery_config_form'
node_gallery_lightbox2_form_alter in contrib/node_gallery_lightbox2/node_gallery_lightbox2.module
Implementation of hook_form_alter()
node_gallery_menu in ./node_gallery.module
Implementation of hook_menu().

File

./node_gallery.admin.inc, line 54
Node gallery admin page file

Code

function node_gallery_config_form($form_state, $gallery_config = NULL) {
  static $node_types, $image_types, $imagecaches;
  if (empty($imagecaches)) {
    foreach (imagecache_presets() as $id => $imagecache) {
      $imagecaches[$imagecache['presetname']] = $imagecache['presetname'];
    }
  }
  if (empty($imagecaches)) {
    form_set_error('Node gallery config', t('There are no imagecache presets. <a href="@imagecache">You must create at least one preset</a>.', array(
      '@imagecache' => url('admin/build/imagecache/add'),
    )));
  }
  $gallery_config = array_merge((array) $gallery_config, (array) $form_state['storage']);
  $gallery_config = array_merge($gallery_config, (array) $form_state['values']['config']);

  //for other module like node_gallery_lightbox2 use.
  $form['#gallery_config'] = $gallery_config;
  $step = empty($form_state['values']['step']) ? 1 : 2;
  $form['step'] = array(
    '#type' => 'hidden',
    '#value' => $step,
  );
  $form['config'] = array(
    '#tree' => TRUE,
  );
  if ($step == 1) {
    if (empty($node_types)) {
      foreach (node_get_types() as $node_type) {
        $node_types[$node_type->type] = $node_type->name;
      }
    }
    $form['config']['gallery_type'] = array(
      '#type' => 'radios',
      '#title' => t('Gallery Type'),
      '#options' => $node_types,
      '#description' => t('Select which content type should be used as the gallery type.'),
      '#default_value' => $gallery_config['gallery_type'],
      '#required' => TRUE,
    );
    $form['config']['image_type'] = array(
      '#type' => 'radios',
      '#title' => t('Image Type'),
      '#options' => $node_types,
      '#description' => t('Select which content type should be used as the image type.'),
      '#default_value' => $gallery_config['image_type'],
      '#required' => TRUE,
    );
    $form['next'] = array(
      '#type' => 'submit',
      '#value' => t('Next'),
      '#submit' => array(
        'node_gallery_config_form_next_submit',
      ),
    );
  }
  else {
    drupal_add_js(drupal_get_path('module', 'node_gallery') . '/node_gallery.admin.js', 'module');

    /*cck support*/
    if (module_exists('content')) {
      content_clear_type_cache();
      $image_type = content_types($form_state['storage']['image_type']);

      //non-cck fields
      foreach ($image_type['extra'] as $name => $field) {
        if ($name != 'menu' && $name != 'attachments') {
          $image_type_fields[$name] = $field['label'];
        }
      }

      //cck fields
      foreach ($image_type['fields'] as $name => $field) {
        $image_type_fields[$name] = $field['widget']['label'];
      }
    }
    else {
      $node_fields = node_gallery_get_type_fields($form_state['storage']['image_type']);
      foreach ($node_fields as $name => $field) {
        $image_type_fields[$name] = $field['label'];
      }
    }
    $form['config']['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Gallery Type Name'),
      '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the create content page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and <strong>spaces</strong>.'),
      '#maxlength' => 32,
      '#required' => TRUE,
      '#default_value' => $gallery_config['name'],
    );
    $form['config']['gallery_directory'] = array(
      '#type' => 'textfield',
      '#title' => t('Gallery Directory'),
      '#description' => t('Specify a subdirectory of the file system where the images for the galleries will be saved. The document root is \'files\'.
       Use %uid for user_id, %username for username, %gid for gallery_id, %gallery_name for gallery_name.'),
      '#default_value' => $gallery_config['gallery_directory'],
    );
    $form['config']['default_cover'] = array(
      '#type' => 'textfield',
      '#title' => t('Default Cover Image'),
      '#description' => t('Specify a default cover image to show when there are no images in the gallery. The path begins with your drupal root. <strong>Do not include the leading slash /.</strong>'),
      '#default_value' => $gallery_config['default_cover'],
    );
    $form['config']['number_uploads'] = array(
      '#type' => 'select',
      '#title' => t('Number of Uploads'),
      '#options' => drupal_map_assoc(range(1, 20)),
      '#multiple' => FALSE,
      '#description' => t('This allows you to specify how many image upload fields appear on the image upload page. By default, only 5 fields are provided. We recommend you do not have more than 5 fields if you are on a shared host or have limited resources. If you increase this to more than 5, we highly recommend you test this by uploading lots of large images prior to putting your site into production.'),
      '#default_value' => empty($gallery_config['number_uploads']) ? '5' : $gallery_config['number_uploads'],
    );
    $form['config']['display_fields'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Fields'),
      '#options' => $image_type_fields,
      '#description' => t('Specify which fields should be displayed.'),
      '#required' => TRUE,
      '#default_value' => empty($gallery_config['display_fields']) ? array() : $gallery_config['display_fields'],
    );
    $form['config']['content_display'] = array(
      '#type' => 'radios',
      '#title' => t('Choose the content you want to display'),
      '#options' => array(
        'gallery' => t('Gallery'),
        'image' => t('Images'),
      ),
      '#description' => t("If you select 'Gallery', the body text of the gallery node will be used. If you select 'Images', the body text of the image node will be used. This allows you choose if you want the text content with each image to be different or the same on all images."),
      '#default_value' => empty($gallery_config['content_display']) ? 'image' : $gallery_config['content_display'],
    );
    $form['config']['image_comment'] = array(
      '#type' => 'radios',
      '#title' => t('Image Comment Setting'),
      '#options' => array(
        'image' => t('Use the image type comment settings.'),
        'gallery' => t('Use the gallery type comment settings.'),
      ),
      '#description' => t('Select how to apply comments to the images.'),
      '#default_value' => isset($gallery_config['image_comment']) ? $gallery_config['image_comment'] : 'image',
    );

    //gallery image size setting
    $form['config']['image_size'] = array(
      '#type' => 'fieldset',
      '#title' => t('Image Sizes'),
      '#description' => t('Specify the imagecache preset to use for each type of gallery image.'),
      '#tree' => TRUE,
    );
    $form['config']['image_size']['cover'] = array(
      '#type' => 'select',
      '#title' => t('Cover'),
      '#options' => $imagecaches,
      '#default_value' => $gallery_config['image_size']['cover'],
    );
    $form['config']['image_size']['thumbnail'] = array(
      '#type' => 'select',
      '#title' => t('Thumbnail'),
      '#options' => $imagecaches,
      '#default_value' => $gallery_config['image_size']['thumbnail'],
    );
    $form['config']['image_size']['preview'] = array(
      '#type' => 'select',
      '#title' => t('Preview: This will be the Image Display (A Preview of the Full-Size Image)'),
      '#options' => $imagecaches,
      '#default_value' => $gallery_config['image_size']['preview'],
    );

    /*$extra_options = array();
      $extra_description = '';
      if ($lightbox2) {
        $extra_options['lightbox2'] = t('Enable as Lightbox2 Popup');
      }
      else {
        $extra_description = '<br />'. t('If you install and enable the <a href="http://drupal.org/project/lightbox2">Lightbox2</a> module, you can use Lightbox to display a larger version of the image.');
      }*/
    $form['config']['original'] = array(
      '#type' => 'fieldset',
      '#title' => t('Original Image Display'),
      '#description' => t('Specify how to display the original image or disable this feature.'),
      '#tree' => TRUE,
    );
    $form['config']['original']['view_original'] = array(
      '#type' => 'radios',
      '#title' => t('View of The Original Image'),
      '#attributes' => array(
        'class' => 'view-original-radios',
      ),
      '#options' => array(
        '0' => t('Disabled'),
        'default' => t('Enable as a link over the displayed image'),
        'text' => t('Enable as text link below the displayed image'),
      ),
      '#description' => t('Specify whether to allow viewing the original image and how to do so.'),
      '#default_value' => isset($gallery_config['original']['view_original']) ? $gallery_config['original']['view_original'] : 0,
    );
    $form['config']['original']['view_original_text'] = array(
      '#type' => 'textfield',
      '#title' => t('View Original Image Text Link'),
      '#description' => t('If you have selected the "Enable Text Link Below the Displayed Image" option, enter the text for the link.'),
      '#default_value' => empty($gallery_config['original']['view_original_text']) ? t('Download the Original Image') : $gallery_config['original']['view_original_text'],
      '#prefix' => '<div class="view-original-text-value">',
      '#suffix' => '</div>',
    );

    //gallery teaser image display setting
    $form['config']['teaser'] = array(
      '#type' => 'fieldset',
      '#title' => t('Teaser Setting'),
      '#description' => t('Specify how to display the gallery when viewing the gallery node as a teaser.'),
    );
    $form['config']['teaser']['gallery_display_type'] = array(
      '#type' => 'radios',
      '#title' => t('Display Type'),
      '#attributes' => array(
        'class' => 'teaser-display-type-radios',
      ),
      '#options' => array(
        'cover' => t('Cover'),
        'thumbnails' => t('Thumbnails'),
      ),
      '#default_value' => empty($gallery_config['teaser']['gallery_display_type']) ? 'cover' : $gallery_config['teaser']['gallery_display_type'],
    );
    $form['config']['teaser']['thumbnails_num'] = array(
      '#type' => 'textfield',
      '#title' => t('Number of Thumbnails to Display'),
      '#description' => t('If thumbnails are selected as the display type above, enter the number of thumbnails to show in the teaser.'),
      '#default_value' => $gallery_config['teaser']['thumbnails_num'],
    );
    $form['config']['teaser']['image'] = array(
      '#type' => 'select',
      '#title' => t('Image Size for Display Type'),
      '#options' => $imagecaches,
      '#description' => t('Select the Imagecache preset that will be used for the display type selected above.'),
      '#default_value' => $gallery_config['teaser']['image'],
    );

    /**
     * Gallery Landing page
     */
    $form['config']['gallery'] = array(
      '#type' => 'fieldset',
      '#title' => t('Gallery Landing Page Setting'),
      '#description' => t('Specify how to display the gallery landing page images when viewing the node as a teaser'),
    );
    $form['config']['gallery']['gallery_display_type'] = array(
      '#type' => 'radios',
      '#title' => t('Gallery Display Type'),
      '#attributes' => array(
        'class' => 'gallery-display-type-radios',
      ),
      '#options' => array(
        'thumbnails' => t('Thumbnails'),
        'cover' => t('Cover'),
      ),
      '#default_value' => empty($gallery_config['gallery']['gallery_display_type']) ? 'thumbnails' : $gallery_config['gallery']['gallery_display_type'],
    );

    //gallery upload limitation settings;
    node_gallery_upload_limits_form($form, $gallery_config['upload_limits'], $gallery_config['image_type']);
    $form['previous'] = array(
      '#type' => 'submit',
      '#value' => t('Previous'),
      '#submit' => array(
        'node_gallery_config_form_prev_submit',
      ),
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
    );
  }
  return $form;
}