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
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | views-582228.patch | 562 bytes | dawehner |
Comments
Comment #1
merlinofchaos commentedCan you supply a patch?
Comment #2
dawehnerComment #3
dankohn commentedThis 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.
Comment #4
momper commentedsubscribe
Comment #5
Bojhan commentedCan I apply this to a specific Vocabulary just as All terms?
Comment #6
merlinofchaos commentedBojhan: 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.
Comment #7
dawehnerAlternative, i could write such an handler, too.
Comment #8
merlinofchaos commentedUpon 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.
Comment #9
esmerel commentedOK, 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)
Comment #10
dawehnerI think this might be something for drupalcon, but i cannot promise something.
Comment #11
michellezeedru commentedSubscribing
Comment #12
raulmuroc commentedSubscribing.
Comment #13
wfx commentedsub
Comment #14
asb commentedWhat is the current status of synonyms support in Views?
Comment #15
asb commentednobody knows anything?
Comment #16
mustanggb commented