You are here

class views_handler_field_amazon_title in Amazon Product Advertisement API 6

Same name in this branch
  1. 6 includes/views_handler_field_amazon_title.inc \views_handler_field_amazon_title
  2. 6 includes/views_handler_filter_amazon_node_module.inc \views_handler_field_amazon_title
Same name and namespace in other branches
  1. 7.2 includes/views_handler_field_amazon_title.inc \views_handler_field_amazon_title
  2. 7 includes/views_handler_field_amazon_title.inc \views_handler_field_amazon_title

Hierarchy

Expanded class hierarchy of views_handler_field_amazon_title

2 string references to 'views_handler_field_amazon_title'
amazon_views_data in includes/amazon.views.inc
amazon_views_handlers in includes/amazon.views.inc
Implementation of hook_views_handlers()

File

includes/views_handler_field_amazon_title.inc, line 3

View source
class views_handler_field_amazon_title extends views_handler_field {
  function options(&$options) {
    parent::options($options);
    $options['link_format'] = 'amazon';
  }

  /**
   * Override init function to provide generic option to link to node.
   */
  function init(&$view, &$data) {
    parent::init($view, $data);
    if (!empty($data['link_format']) && $data['link_format'] == 'amazon') {
      $this->additional_fields[] = 'detailpageurl';
    }
    $this->additional_fields[] = 'asin';
  }

  /**
   * Provide link to node option
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['link_format'] = array(
      '#title' => t('Link behavior'),
      '#type' => 'radios',
      '#options' => array(
        'plain' => t('No link'),
        'amazon' => t("A link to the product's Amazon page"),
      ),
      '#default_value' => !empty($this->options['link_format']) ? $this->options['link_format'] : 'plain',
    );
    if ($this->view->base_table == 'node') {
      $form['link_format']['#options']['node'] = t('A link to the node the product is associated with');
    }
    if (module_exists('amazon_store')) {
      $form['link_format']['#options']['amazon_store'] = t("A link to the product's Amazon Store page (Amazon Store Module)");
    }
  }
  function render($values) {
    $title = check_plain($values->{$this->field_alias});
    switch ($this->options['link_format']) {
      case 'plain':
        return $title;
        break;
      case 'node':
        return l($title, 'node/' . $values->nid, array(
          'html' => TRUE,
        ));
        break;
      case 'amazon':
        return l($title, check_url($values->{$this->table_alias . '_detailpageurl'}), array(
          'html' => TRUE,
        ));
        break;
      case 'amazon_store':
        $path = function_exists('amazon_store_get_amazon_store_path') ? amazon_store_get_amazon_store_path() : 'amazon_store';
        $asin = $values->{$this->aliases['asin']};
        return l($title, "{$path}/item/{$asin}", array(
          'html' => TRUE,
        ));
        break;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_handler_field_amazon_title::init function Override init function to provide generic option to link to node.
views_handler_field_amazon_title::options function
views_handler_field_amazon_title::options_form function Provide link to node option
views_handler_field_amazon_title::render function