You are here

function asin_field_widget_settings_form in Amazon Product Advertisement API 7

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

Implements hook_field_widget_settings_form().

File

asin/asin.module, line 179
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'];
    }
  }
  if ($widget['type'] == 'asin_autocomplete') {
    $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',
      ),
    );
    if (isset($settings['widget_settings']['locale'])) {
      $form['widget_settings']['productgroup'] = array(
        '#title' => t('Search Index'),
        '#type' => 'select',
        '#options' => $cache['locales'][$settings['widget_settings']['locale']]['search_indexes'],
        '#default_value' => isset($settings['widget_settings']['productgroup']) ? $settings['widget_settings']['productgroup'] : 'All',
      );
    }
    return $form;
  }
}