I was using Views to build some block based on taxonomy terms when I found that there was no field to allow synonyms to be output in the block. I need this - so presumably there must be others. Maybe it could be included in the module code in future?

I found it was easy to fix: edit the file "\sites\all\modules\views\modules\taxonomy.views.inc" - the bit dealing with the term_synonym table starts at line 272 in my copy:

  // ----------------------------------------------------------------------
  // term_synonym table

  $data['term_synonym']['table']['group']  = t('Taxonomy');

  $data['term_synonym']['table']['join'] = array(
    'term_data' => array(
      // links directly to term_data via tid
      'left_field' => 'tid',
      'field' => 'tid',
    ),
    'node' => array(
      'left_table' => 'term_node',
      'left_field' => 'tid',
      'field' => 'tid',
    ),
    'node_revisions' => array(
      'left_table' => 'term_node',
      'left_field' => 'tid',
      'field' => 'tid',
    ),
  );

  $data['term_synonym']['name'] = array(
    'title' => t('Term synonym'),
    'help' => t('Term synonyms may be used to find terms by alternate names.'),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
      'many to one' => TRUE,
      'empty field name' => t('Uncategorized'),
    ),
  );
  return $data;
}

Add an entry for "field" to the $data['term_synonym']['name'] array as follows:

  $data['term_synonym']['name'] = array(
    'title' => t('Term synonym'),
    'help' => t('Term synonyms may be used to find terms by alternate names.'),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
      'many to one' => TRUE,
      'empty field name' => t('Uncategorized'),
    ),
    'field' => array(
      'field' => 'name', // the real field
      'group' => t('Taxonomy'), // The group it appears in on the UI,
      'handler' => 'views_handler_field_markup',
      'format' => FILTER_FORMAT_DEFAULT,
    ),
  );

A new entry called "Term synonym" will now appear in the list of fields under the "Taxonomy" heading. (NB. You need to empty your cache, after saving this change before it will take effect).

Stuart

CommentFileSizeAuthor
#2 views-582228.patch562 bytesdawehner

Comments

merlinofchaos’s picture

Can you supply a patch?

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new562 bytes
dankohn’s picture

This patch works for me and is a valuable addition to views.

Also, a related feature request. It would be great to be able to filter on the synonym field to only run the view if a synonym exists.

momper’s picture

subscribe

Bojhan’s picture

Can I apply this to a specific Vocabulary just as All terms?

merlinofchaos’s picture

Bojhan: Currently this patch does a simple join so you'll get duplicates and stuff. The All Terms performs a second query, and this would need to to accomplish that.

I'm trying to decide if that should happen for this patch. Thinking about it. Not sure.

dawehner’s picture

Alternative, i could write such an handler, too.

merlinofchaos’s picture

Status: Needs review » Needs work

Upon thinking about it, yes, we do want an All Synonyms, but it should be per term, not per node. There wouldn't need to be a vocabulary selector for it. Sending this back to needs work land for that.

esmerel’s picture

OK, anyone want to fix this patch? If not, the next time I come around for it, I'm going to won't fix it (90 days)

dawehner’s picture

I think this might be something for drupalcon, but i cannot promise something.

michellezeedru’s picture

Subscribing

raulmuroc’s picture

Subscribing.

wfx’s picture

sub

asb’s picture

What is the current status of synonyms support in Views?

asb’s picture

Version: 6.x-2.6 » 6.x-3.x-dev

nobody knows anything?

mustanggb’s picture

Status: Needs work » Closed (won't fix)