You are here

function asin_field_widget_settings_form in Amazon Product Advertisement API 7.2

Same name and namespace in other branches
  1. 7 asin/asin.module \asin_field_widget_settings_form()

Implements hook_field_widget_settings_form().

File

asin/asin.module, line 221
Defines a field type for referencing an Amazon product.

Code

function asin_field_widget_settings_form($field, $instance) {
  $widget = $instance['widget'];
  $settings = $widget['settings'];
  $cache = amazon_data_cache();
  $locale_options = array(
    '' => '-- Select --',
  );
  foreach ($cache['locales'] as $locale => $data) {
    if (variable_get('amazon_locale_' . $locale . '_associate_id', '')) {
      $locale_options[$locale] = $data['name'];
    }
  }
  $form['widget_settings'] = array(
    '#prefix' => '<div id="asin-autocomplete-widget-settings">',
    '#suffix' => '</div>',
  );
  $form['widget_settings']['locale'] = array(
    '#title' => t('Amazon Locale'),
    '#type' => 'select',
    '#options' => $locale_options,
    '#default_value' => isset($settings['widget_settings']['locale']) ? $settings['widget_settings']['locale'] : '',
    '#required' => TRUE,
    '#ajax' => array(
      'wrapper' => 'asin-autocomplete-widget-settings',
      'callback' => 'asin_widget_locale_product_group',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );

  // Default value for the dropdown.
  $productgroup_options = array(
    'All' => 'All indexes',
  );
  if (isset($settings['widget_settings']['locale'])) {
    if (isset($cache['locales'][$settings['widget_settings']['locale']]['search_indexes'])) {

      // Populate list.
      $productgroup_options = $cache['locales'][$settings['widget_settings']['locale']]['search_indexes'];
    }
  }
  if ($instance['widget']['type'] == 'asin_autocomplete') {
    $form['widget_settings']['productgroup'] = array(
      '#title' => t('Search Index'),
      '#type' => 'select',
      '#options' => $productgroup_options,
      '#default_value' => isset($settings['widget_settings']['productgroup']) ? $settings['widget_settings']['productgroup'] : 'All',
    );
  }
  return $form;
}