Only mention of term_relation is a lil comment with "TODO".

Based on the lack of any issue about it, generally guess no one desired this before (only one result for term_relation, and that was a list of someone's tables).

Anyhow I made a quick thing for being able to get term list based on term_relation argument
Will make a patch if this is desired, but personally dislike how I did it, and not much desire in general it seems for it, etc... so don't see it being used (stuffed in a personal module At the moment). But might as well post it


function multivocabrelatedterm_views_data() {
  $data = array();
  $data['term_data']['term_relationship'] = array(
    'group' => t('Taxonomy'),
    'title' => t('Term relation'),
    'help' => t('Related term.'),
    'real field' => 'tid',
    'argument' => array(
      'handler' => 'views_handler_argument_term_data_term_relationship',
    ),
  );
  return $data;
}

function multivocabrelatedterm_views_handlers() {
  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'multivocabrelatedterm'),
    ),
    'handlers' => array(
      'views_handler_argument_term_data_term_relationship' => array(
        'parent' => 'views_handler_argument',
      ),
    ),
  );
}

and the handler (or at github http://github.com/hefox/vocabulary/blob/master/multivocabrelatedterm/vie...)

/**
 */
class views_handler_argument_term_data_term_relationship extends views_handler_argument {
  function query() {
    $this->ensure_my_table();
    $args = array($this->argument,$this->argument);
    $this->query->add_where(0, "$this->table_alias.tid in (SELECT tid2 from {term_relation} where tid1 = %d) OR $this->table_alias.tid in (SELECT tid1 from {term_relation} where tid2 = %d)", $args); // Ewwww 
  }

  function title() {
    $term = taxonomy_get_term($this->argument);
    if (!empty($term)) {
      return check_plain($term->name);
    }
    // TODO review text
    return t('No name');
  }
}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gerhard Killesreiter’s picture

Version: 6.x-2.8 » 6.x-2.x-dev
Status: Active » Needs review
FileSize
1.48 KB

Here's a slightly different patch that works for me.

hefox’s picture

I much prefer how clean your patch is, but it doesn't handle the bidirectional use case (which was my use case).

Hm, perhaps combine the two, with the bidirectional being the "Advanced" (... or just "Bidirectional). But I'd really like a cleaner way to do it then I ended up doing it (ugly!). I believe there's others arguments in taxonomy views intergration that already set the precedent that something can have an advanced argument (the depth ones)?

merlinofchaos’s picture

Can you explain the bi-directional use case to me?

hefox’s picture

Hm, calling it bidirectional may have been a incorrect term.

I was using a module that allowed me to use multiple vocabularies for related terms (I made a module, then found one that actually did it on d.o, sigh; there's nothing preventing this in core other than a lack of form to save it :O). Anyhow just saying that as it may make my use case more clear.

Sowhen on a term in vocabulary 'series' I marked terms of 'characters' as related.. and marked related series when creating characters, so series 1 could be related to characters 2, 3, 4 but as the table could look like...
tid1, tid2
1, 2
3, 1
4, 1

So if I want to make a listing of all those related to series 1, I need to look in tid1 and tid2 for that 1.

Anyhow, in the end I switched over to using a ctools 'content type' so not going to push for it, but there's is a bit of a use case for it XD.

merlinofchaos’s picture

Ok, I've decided that hefox's case is not one we need to support, so committed killes' patch to all branches.

dawehner’s picture

Status: Needs review » Patch (to be ported)

so this is fixed?
I guess you know that this will not work for v7, because the taxonomy implementation is totally different in d7.

tim.plunkett’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.