You are here

function taxonomy_views_tables in Views (for Drupal 7) 5

This include file implements views functionality on behalf of taxonomy.module

File

modules/views_taxonomy.inc, line 7

Code

function taxonomy_views_tables() {
  if (module_exists('taxonomy')) {
    $table = views_new_table('term_node', 'internal', 'node', 'nid', 'nid');
    views_table_add_field($table, 'name', 'Taxonomy: All Terms', 'This will display all taxonomy terms associated with the node. Note that this causes one extra query per row displayed, and might have a minor performance impact.', array(
      'sortable' => false,
      'handler' => 'views_handler_field_allterms',
      'option' => array(
        '#type' => 'select',
        '#options' => array(
          'link' => 'As links',
          'nolink' => 'Without links',
        ),
      ),
      'notafield' => true,
    ));
    views_table_add_filter($table, 'tid', 'Taxonomy: Term', 'When filtering by taxonomy term you may specify the "depth" as an option. Please see the taxonomy help for more information.', array(
      'list' => 'views_handler_filter_tid',
      'option' => 'string',
      'operator' => 'views_handler_operator_andor',
      'handler' => 'views_handler_filter_tid_custom',
      'value-type' => 'array',
    ));
    $tables[$table['name']] = $table;
    $vocabularies = taxonomy_get_vocabularies();
    foreach ($vocabularies as $voc) {
      $tables["term_node_{$voc->vid}"] = array(
        'name' => 'term_node',
        'provider' => 'internal',
        'join' => array(
          'left' => array(
            'table' => 'node',
            'field' => 'nid',
          ),
          'right' => array(
            'field' => 'nid',
          ),
        ),
        'fields' => array(
          'name' => array(
            'name' => t('Taxonomy: Terms for @voc-name', array(
              '@voc-name' => $voc->name,
            )),
            'sortable' => false,
            'help' => t('This will display all taxonomy terms associated with the node that are members of %voc-name. Note that this causes one extra query per row displayed, and might have a minor performance impact.', array(
              '%voc-name' => $voc->name,
            )),
            'handler' => 'views_handler_field_allterms',
            'vocabulary' => $voc->vid,
            'notafield' => true,
            'option' => array(
              '#type' => 'select',
              '#options' => array(
                'link' => 'As links',
                'nolink' => 'Without links',
              ),
            ),
          ),
        ),
        'filters' => array(
          'tid' => array(
            'name' => t('Taxonomy: Terms for @voc-name', array(
              '@voc-name' => $voc->name,
            )),
            'value' => views_taxonomy_form($voc),
            //views does handle this as array regardless what we state here due to the operators
            'value-type' => 'array',
            'tags' => $voc->tags,
            'operator' => 'views_handler_operator_andor',
            'handler' => 'views_handler_filter_tid_custom',
            'option' => 'string',
            'vocabulary' => $voc->vid,
            'help' => t("Only terms associated with %voc-name will appear in the select box for this filter. When filtering by taxonomy term you may specify the 'depth' as an option. Please see the taxonomy help for more information.", array(
              '%voc-name' => $voc->name,
            )),
          ),
        ),
      );
    }
    $tables['term_hierarchy'] = array(
      'name' => 'term_hierarchy',
      'provider' => 'internal',
      'join' => array(
        'left' => array(
          'table' => 'term_node',
          'field' => 'tid',
        ),
        'right' => array(
          'field' => 'tid',
        ),
      ),
    );
    $tables['term_data'] = array(
      'name' => 'term_data',
      'provider' => 'internal',
      'join' => array(
        'left' => array(
          'table' => 'term_node',
          'field' => 'tid',
        ),
        'right' => array(
          'field' => 'tid',
        ),
      ),
      'fields' => array(
        'name' => array(
          'name' => t('Taxonomy: Term'),
          'sortable' => true,
          'handler' => array(
            'views_handler_field_tid' => "No link",
            'views_handler_field_tid_link' => "With link",
          ),
          'addlfields' => array(
            'tid',
          ),
          'help' => t('This will display one of the taxonomy terms associated with the node; if taxonomy terms were used to filter or sort, it will be the one that triggered the sort or filter.'),
        ),
        'description' => array(
          'name' => t('Taxonomy: Term Description'),
          'sortable' => false,
          'help' => t('This will display the description associated with a taxonomy term.'),
        ),
      ),
      'sorts' => array(
        'weight' => array(
          'name' => t('Taxonomy: Term Name'),
          'field' => array(
            'weight',
            'name',
          ),
          'help' => t('This will sort nodes by taxonomy weight and name, as defined in the category administration.'),
        ),
      ),
      'filters' => array(
        'vid' => array(
          'name' => t('Taxonomy: Vocabulary Name'),
          'list' => 'views_handler_filter_vid',
          'operator' => 'views_handler_operator_andor',
          'handler' => 'views_handler_filter_voc',
          'value-type' => 'array',
          'help' => t('This will filter a view to only nodes that contain a term in the associated vocabulary.'),
        ),
      ),
    );
    $table = views_new_table('vocabulary', 'internal', 'term_data', 'vid', 'vid');
    $tables['vocabulary'] = $table;
  }
  return $tables;
}