You are here

views_handler_relationship_recommender_entity_type.inc in Recommender API 6.3

File

views/views_handler_relationship_recommender_entity_type.inc
View source
<?php

/**
 * Argument by entity type [#1191904]
 */
class views_handler_relationship_recommender_entity_type extends views_handler_relationship {
  function init(&$view, &$options) {
    parent::init($view, $options);

    // change the base table and base table field based on user input.
    $base_type = isset($options['base_entity_type']) ? $options['base_entity_type'] : 'node';
    $base_table = views_fetch_data($base_type);
    $this->definition['base'] = $base_type;
    $this->definition['base field'] = $base_table['table']['base']['field'];
  }
  function option_definition() {
    $options = parent::option_definition();
    $options['base_entity_type'] = array(
      'default' => 'node',
    );
    return $options;
  }
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $base_tables = views_fetch_base_tables();
    $entity_options = array();
    foreach ($base_tables as $name => $table) {
      $entity_options[$name] = $table['title'];
    }
    $form['base_entity_type'] = array(
      '#type' => 'select',
      '#title' => t('Entity type (base table)'),
      '#default_value' => isset($this->options['base_entity_type']) ? $this->options['base_entity_type'] : 'node',
      '#options' => $entity_options,
      '#description' => t('Select the entity type (node, user, etc) of the recommended items.'),
    );
  }

}

Classes

Namesort descending Description
views_handler_relationship_recommender_entity_type Argument by entity type [#1191904]