You are here

function asin_field_settings in Amazon Product Advertisement API 6

Implementation of hook_field_settings().

File

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

Code

function asin_field_settings($op, $field) {
  switch ($op) {
    case 'database columns':
      $columns['asin'] = array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => FALSE,
      );
      return $columns;
    case 'views data':
      $data = content_views_field_views_data($field);
      $db_info = content_database_info($field);
      $table_alias = content_views_tablename($field);

      // Filter: Add a 'many to one' filter.
      $copy = $data[$table_alias][$field['field_name'] . '_asin'];
      $copy['title'] = t('@label (!name) - Allowed values', array(
        '@label' => $field['widget']['label'],
        '!name' => $field['field_name'],
      ));
      $copy['filter']['handler'] = 'views_handler_filter_many_to_one';
      unset($copy['field'], $copy['argument'], $copy['sort']);
      $data[$table_alias][$field['field_name'] . '_value_many_to_one'] = $copy;

      // Argument : swap the handler to the 'many to one' operator.
      $data[$table_alias][$field['field_name'] . '_value']['argument']['handler'] = 'views_handler_argument_many_to_one';

      // Add a relationship for related node.
      $data[$table_alias][$field['field_name'] . '_asin']['relationship'] = array(
        'base' => 'amazon_item',
        'field' => $db_info['columns']['asin']['column'],
        'handler' => 'views_handler_relationship',
      );
      return $data;
  }
}