You are here

function amazon_settings_form in Amazon Product Advertisement API 6

Same name and namespace in other branches
  1. 7.2 amazon.admin.inc \amazon_settings_form()
  2. 7 amazon.admin.inc \amazon_settings_form()
1 string reference to 'amazon_settings_form'
amazon_menu in ./amazon.module
Implementation of hook_menu. Adds the url path for the Amazon settings page.

File

./amazon.admin.inc, line 3

Code

function amazon_settings_form($form_state) {
  $cache = amazon_data_cache();
  $options = array();
  foreach ($cache['locales'] as $locale => $data) {
    $options[$locale] = $data['name'];
  }
  $form['amazon_locale'] = array(
    '#type' => 'select',
    '#title' => t('Amazon locale'),
    '#default_value' => variable_get('amazon_locale', 'US'),
    '#options' => $options,
    '#description' => t('Amazon.com uses separate product databases and Ecommerce features in different locales; pricing and availability information, as well as product categorization, differs from one locale to the next. Be sure to select the locale your site will be running in.'),
  );
  $form['amazon_associate_setting'] = array(
    '#type' => 'select',
    '#title' => t('Amazon referral settings'),
    '#default_value' => variable_get('amazon_associate_setting', 'association'),
    '#options' => array(
      'association' => t('Use the Drupal Association\'s associate ID'),
      'custom' => t('Use your own associate ID'),
    ),
    '#description' => t('Outgoing links to Amazon.com can include an associate ID code. When shoppers purchase Amazon products via one of those links, the associate ID is used to determine who should receive a referral bonus from Amazon.com.'),
  );
  $form['amazon_custom_associate_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Your associate ID'),
    '#description' => t('Enter your own associate ID to receive referral bonuses when shoppers purchase Amazon products via your site.'),
    '#default_value' => variable_get('amazon_custom_associate_id', ''),
    '#prefix' => '<div id="amazon-associate-id-wrapper">',
    '#suffix' => '</div>',
  );
  if (variable_get('amazon_associate_setting', 'association') != 'custom') {
    $form['amazon_custom_associate_id']['#prefix'] = '<div id="amazon-associate-id-wrapper" class="js-hide">';
  }
  $form['amazon_aws_access_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Amazon AWS Access Key ID'),
    '#description' => t('You must sign up for an Amazon AWS account to use the Product Advertising Service. See !more_info for information and a registration form.', array(
      '!more_info' => l(t('the AWS home page'), 'https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key', array(
        'html' => TRUE,
      )),
    )),
    '#default_value' => variable_get('amazon_aws_access_key', ''),
    '#required' => TRUE,
  );
  $form['amazon_aws_secret_access_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Amazon AWS Secret Access Key'),
    '#description' => t('You must sign up for an Amazon AWS account to use the Product Advertising Service. See !more_info for information and a registration form.', array(
      '!more_info' => l(t('the AWS home page'), 'https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key', array(
        'html' => TRUE,
      )),
    )),
    '#default_value' => variable_get('amazon_aws_secret_access_key', ""),
    '#required' => TRUE,
  );
  $form['default_image'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default image to use when Amazon does not provide an image'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  if (module_exists('imagecache')) {
    $form['#attributes'] = array(
      'enctype' => "multipart/form-data",
    );
    $default_image = variable_get('amazon_default_image', '');
    if (!empty($default_image)) {
      $preset = variable_get('amazon_default_image_small_preset', '');
      if (!empty($preset)) {
        $themed_image = theme('imagecache', $preset, $default_image, t('Amazon default image'));
      }
      else {
        $themed_image = theme('image', $default_image);
      }
      $form['default_image']['existing_image'] = array(
        '#type' => 'markup',
        '#value' => $themed_image,
      );
    }
    $form['default_image']['amazon_default_image'] = array(
      '#type' => 'file',
      '#title' => t('Default image to be used when no image is available'),
      '#size' => 20,
      '#default_value' => $default_image,
    );
    $imagecache_presets = array(
      '' => t('Select a preset'),
    );
    foreach (imagecache_presets() as $preset) {
      $imagecache_presets[$preset['presetname']] = $preset['presetname'];
    }
    $form['default_image']['amazon_default_image_large_preset'] = array(
      '#title' => 'Imagecache preset for "large" size',
      '#type' => 'select',
      '#options' => $imagecache_presets,
      '#default_value' => variable_get('amazon_default_image_large_preset', ''),
    );
    $form['default_image']['amazon_default_image_medium_preset'] = array(
      '#title' => 'Imagecache preset for "medium" size',
      '#type' => 'select',
      '#options' => $imagecache_presets,
      '#default_value' => variable_get('amazon_default_image_medium_preset', ''),
    );
    $form['default_image']['amazon_default_image_small_preset'] = array(
      '#title' => 'Imagecache preset for "small" size',
      '#type' => 'select',
      '#options' => $imagecache_presets,
      '#default_value' => variable_get('amazon_default_image_small_preset', ''),
    );
  }
  else {
    $form['default_image']['if_imagecache'] = array(
      '#type' => 'markup',
      '#value' => t('If imagecache were installed you could set a default image'),
    );
  }

  // Now add the Javascript that does the fancy hide/show effects.
  drupal_add_js(drupal_get_path('module', 'amazon') . '/amazon.admin.js');
  return system_settings_form($form);
}