You are here

function node_gallery_config_form in Node Gallery 6

Same name and namespace in other branches
  1. 6.2 node_gallery.admin.inc \node_gallery_config_form()
1 string reference to 'node_gallery_config_form'
node_gallery_menu in ./node_gallery.module
Implementation of hook_menu()

File

./node_gallery.admin.inc, line 33
Node gallery admin file.

Code

function node_gallery_config_form($form_state, $gallery_config = NULL) {
  $form = array();
  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('No imagecache preset now. You must set at least one.'));
  }
  if (empty($gallery_config)) {
    drupal_set_title(t('Add Gallery Config'));
  }
  else {
    drupal_set_title(t('Edit %name', array(
      '%name' => $gallery_config->name,
    )));
  }
  $gallery_config = empty($gallery_config) ? array() : (array) $gallery_config;
  $gallery_config = empty($form_state['storage']) ? $gallery_config : array_merge($gallery_config, $form_state['storage']);
  $gallery_config = empty($form_state['values']) ? $gallery_config : array_merge($gallery_config, $form_state['values']);
  $form['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'],
  );
  $step = empty($form_state['values']['step']) ? 1 : $form_state['values']['step'] + 1;
  $form['step'] = array(
    '#type' => 'hidden',
    '#value' => $step,
  );
  if ($step == 1) {
    if (empty($node_types)) {
      foreach (node_get_types() as $node_type) {
        $node_types[$node_type->type] = $node_type->name;
      }
    }
    $form['gallery_type'] = array(
      '#type' => 'radios',
      '#title' => t('Gallery Type'),
      '#options' => $node_types,
      '#description' => t('Select which content type should be used as gallery type.'),
      '#default_value' => $gallery_config['gallery_type'],
      '#required' => TRUE,
    );
    $form['image_type'] = array(
      '#type' => 'radios',
      '#title' => t('Image Type'),
      '#options' => $node_types,
      '#description' => t('Select which content type should be used as 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 {

    /*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'];
      }
    }

    //print_r($gallery_config);die;
    $lightbox2 = module_exists('lightbox2');
    drupal_add_js(drupal_get_path('module', 'node_gallery') . '/node_gallery.admin.js', 'module');
    $form['data'] = array(
      '#tree' => TRUE,
    );
    $form['data']['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['data']['gallery_directory'] = array(
      '#type' => 'textfield',
      '#title' => t('Gallery Directory'),
      '#description' => t('Specify a subdirectory of the file system to save the images of your gallery . 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['data']['default_cover'] = array(
      '#type' => 'textfield',
      '#title' => t('Default Cover Image'),
      '#description' => t('Specify a default cover image to show when there is not an image in gallery. The path begins with your drupal root. <strong>Do not include the leading slash /.</strong>'),
      '#default_value' => $gallery_config['default_cover'],
    );
    $form['data']['image_size'] = array(
      '#type' => 'fieldset',
      '#title' => t('Image Sizes'),
      '#description' => t('Specify which imagecache preset you wish to use to display the image.'),
      '#tree' => TRUE,
    );
    $form['data']['image_size']['cover'] = array(
      '#type' => 'select',
      '#title' => t('Cover'),
      '#options' => $imagecaches,
      '#default_value' => $gallery_config['image_size']['cover'],
    );
    $form['data']['image_size']['thumbnail'] = array(
      '#type' => 'select',
      '#title' => t('Thumbnail'),
      '#options' => $imagecaches,
      '#default_value' => $gallery_config['image_size']['thumbnail'],
    );
    $form['data']['image_size']['preview'] = array(
      '#type' => 'select',
      '#title' => t('Preview (This will be your Display--A Preview of the Full-Size Image)'),
      '#options' => $imagecaches,
      '#default_value' => $gallery_config['image_size']['preview'],
    );
    $form['data']['teaser'] = array(
      '#type' => 'fieldset',
      '#title' => t('Teaser Setting'),
      '#description' => t('Specify how to display the gallery and image when viewing the node as a teaser.'),
    );
    $display_extra_options = array();
    if ($lightbox2) {
      $display_extra_options['lightbox2_gallery'] = t('Thumbnails that open a Lightbox2 Gallery');
    }
    $form['data']['teaser']['gallery_display_type'] = array(
      '#type' => 'radios',
      '#title' => t('Display Type'),
      '#attributes' => array(
        'class' => 'teaser-display-type-radios',
      ),
      '#options' => array_merge(array(
        'cover' => t('Cover'),
        'thumbnails' => t('Thumbnails'),
      ), $display_extra_options),
      '#default_value' => empty($gallery_config['teaser']['gallery_display_type']) ? 'cover' : $gallery_config['teaser']['gallery_display_type'],
    );
    $form['data']['teaser']['thumbnails_num'] = array(
      '#type' => 'textfield',
      '#title' => t('Number of Thumbnails to Display'),
      '#description' => t('If you select the gallery display type as thumbnails above, enter the number of thumbnails you want to display when viewing the teaser.'),
      '#default_value' => $gallery_config['teaser']['thumbnails_num'],
    );
    if ($lightbox2) {
      $form['data']['teaser']['lightbox2_gallery'] = array(
        '#type' => 'select',
        '#title' => t('Image Size for Lightbox2 Gallery'),
        '#options' => $imagecaches,
        '#description' => t('Select an Imagecache preset that will be used with the Lightbox2 popup.'),
        '#default_value' => $gallery_config['teaser']['lightbox2_gallery'],
        '#prefix' => '<div class="lightbox2-gallery-preset">',
        '#suffix' => '</div>',
      );
    }
    $form['data']['teaser']['image'] = array(
      '#type' => 'select',
      '#title' => t('Image Size for Teaser Display Type'),
      '#options' => $imagecaches,
      '#default_value' => $gallery_config['teaser']['image'],
    );

    /**
     * Gallery Landing page
     */
    $form['data']['gallery'] = array(
      '#type' => 'fieldset',
      '#title' => t('Gallery Landing Page Setting'),
      '#description' => t('Specify how to display the gallery landing page and image when viewing the node as a teaser.'),
    );
    $gallery_display_extra_options = array();
    $gallery_display_default_value = $gallery_config['gallery']['gallery_display'] == '' ? 'thumbnails' : $gallery_config['gallery']['gallery_display'];
    if ($lightbox2) {
      $gallery_display_extra_options['lightbox2_gallery'] = t('Thumbnails that open a Lightbox2 Gallery');
    }
    else {
      if ($gallery_display_default_value == 'lightbox2_gallery') {

        // We don't want the default to be a radio that doesn't exist
        $gallery_display_default_value = 'thumbnails';
      }
    }
    $form['data']['gallery']['gallery_display'] = array(
      '#type' => 'radios',
      '#title' => t('Gallery Display Type'),
      '#attributes' => array(
        'class' => 'gallery-display-type-radios',
      ),
      '#options' => array_merge(array(
        'cover' => t('Cover'),
        'thumbnails' => t('Thumbnails'),
      ), $gallery_display_extra_options),
      '#default_value' => $gallery_display_default_value,
    );
    if ($lightbox2) {
      $form['data']['gallery']['lightbox2_gallery_preset'] = array(
        '#type' => 'select',
        '#title' => t('Image Size for Lightbox2 Gallery'),
        '#options' => $imagecaches,
        '#description' => t('Select an Imagecache preset that will be used with the Lightbox2 popup.'),
        '#default_value' => $gallery_config['gallery']['lightbox2_gallery_preset'],
        '#prefix' => '<div class="gallery-lightbox2-gallery-preset">',
        '#suffix' => '</div>',
      );
    }
    $form['data']['gallery']['image'] = array(
      '#type' => 'select',
      '#title' => t('Image Size for Gallery Display Type'),
      '#options' => $imagecaches,
      '#default_value' => $gallery_config['gallery']['image'],
    );
    $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 photo.');
    }
    $form['data']['view_original'] = array(
      '#type' => 'radios',
      '#title' => t('View Larger Image'),
      '#attributes' => array(
        'class' => 'view-original-radios',
      ),
      '#options' => array_merge(array(
        '0' => t('Disable'),
        'default' => t('Enable as a Link on the Displayed Image'),
        'text' => t('Enable as Text Link Below the Displayed Image'),
      ), $extra_options),
      '#description' => t('Specify whether allow or not viewing the original image.') . $extra_description,
      '#default_value' => empty($gallery_config['view_original']) ? 0 : $gallery_config['view_original'],
    );
    $form['data']['view_original_text'] = array(
      '#type' => 'textfield',
      '#title' => t('View Original Text Link'),
      '#description' => t('If you have selected the "Enable Text Link Below Displayed Image" option, you should provide some text for the link.'),
      '#default_value' => empty($gallery_config['view_original_text']) ? t('Download the Original Image') : $gallery_config['view_original_text'],
      '#prefix' => '<div class="view-original-text-value">',
      '#suffix' => '</div>',
    );

    // Force the user to select a imagecache preset for lightbox
    if ($lightbox2) {
      $form['data']['lightbox2'] = array(
        '#type' => 'select',
        '#title' => t('Imagecache Preset for Lightbox2'),
        '#options' => $imagecaches,
        '#description' => t('Select an Imagecache preset that will be used with the Lightbox2 popup.  Please note that this preset should be larger than your Display preset.'),
        '#default_value' => $gallery_config['lightbox2'],
        '#prefix' => '<div class="lightbox2-preset">',
        '#suffix' => '</div>',
      );
    }
    $form['data']['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 \n      body text of the Image node will be used. This allows you choose if you want the content display with each image to be different or not."),
      '#default_value' => empty($gallery_config['content_display']) ? 'image' : $gallery_config['content_display'],
    );
    $form['data']['image_comment'] = array(
      '#type' => 'radios',
      '#title' => t('Comment to image'),
      '#options' => array(
        t('Disabled'),
        t('Read only'),
        t('Read/Write'),
      ),
      '#description' => t('Choose whether or not to allow comment to images.'),
      '#default_value' => $gallery_config['image_comment'] == '' ? 2 : $gallery_config['image_comment'],
    );
    $form['data']['upload_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Image Upload Settings'),
      '#description' => t('This allows you to configure the bulk upload page.'),
    );
    $form['data']['upload_settings']['number_uploads'] = array(
      '#type' => 'select',
      '#title' => t('Number of Uploads'),
      '#options' => array(
        '1' => '1',
        '2' => '2',
        '3' => '3',
        '4' => '4',
        '5' => '5',
        '6' => '6',
        '7' => '7',
        '8' => '8',
        '9' => '9',
        '10' => '10',
        '11' => '11',
        '12' => '12',
        '13' => '13',
        '14' => '14',
        '15' => '15',
        '16' => '16',
        '17' => '17',
        '18' => '18',
        '19' => '19',
        '20' => '20',
      ),
      '#multiple' => FALSE,
      '#description' => t('This allows you to specify how many file upload fields appear on the image upload form.  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 resourced.  If you incress this to more than 5, we highly recommend you test this by uploading lots of large files before putting your site into production.'),
      '#default_value' => empty($gallery_config['upload_settings']['number_uploads']) ? '5' : $gallery_config['upload_settings']['number_uploads'],
    );
    $form['previous'] = array(
      '#type' => 'submit',
      '#value' => t('Previous'),
      '#submit' => array(
        'node_gallery_config_form_pre_submit',
      ),
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
    );
  }
  return $form;
}