Hello,

I'd like to create a rule triggered when any taxonomy term belonging to a specific vocabulary is being viewed.
The action needs to use the term id/name and the vocabulary id/name.

My goal is: when a taxonomy term is being viewed, redirect to a view filtered on that term, where filter depends of term's vocabulary (because there are multiple vocabularies and corresponding filters on the same view).

Can this be done?
Thank you.

Comments

phily’s picture

Title: Taxonomy term being viewed event, is part of vacabulary condition » Taxonomy term being viewed event, is part of vocabulary condition
impol’s picture

I solved this problem by declaring custom event using Rules API.

/**
 * Implements hook_rules_event_info().
 */
function modulename_rules_event_info() {
  $defaults_term = array(
    'group' => t('modulename'),
    'access callback' => 'rules_taxonomy_term_integration_access',
    'module' => 'taxonomy',
    'class' => 'RulesTaxonomyEventHandler',
  );

  return array(
    'taxonomy_term_view' => $defaults_term + array(
        'label' => t('After viewing a term'),
        'variables' => array(
          'term' => array('type' => 'taxonomy_term', 'label' => t('Viewed term')),
        ),
      ),
  );
}

/**
 * Implements hook_taxonomy_term_view().
 */
function modulename_taxonomy_term_view($term, $view_mode, $langcode) {  
    rules_invoke_event('taxonomy_term_view', $term);  
}
kryber’s picture

Hallo,

this code is not triggering the event "taxonomy_term_view". Is there any improvements or are conditions, what needs to be done?

Thank you

izmeez’s picture

Title: Taxonomy term being viewed event, is part of vocabulary condition » Event to react on Taxonomy term being viewed to filter by vocabulary
Version: 7.x-2.6 » 7.x-2.x-dev

I'm not sure if this is just a documentation issue or also a code or feature request.

I've changed the title of the issue and hope it helps clarify what I think this issue is about.

Kojo Unsui’s picture

Hi there,

just needed to implement the same. That code is triggering rule fine when a taxonomy term is viewed :

/**
 * Implements hook_rules_event_info().
 */
function modulename_rules_event_info() {
  $defaults_term = array(
    'group' => t('Taxonomy'),
    'access callback' => 'rules_taxonomy_term_integration_access',
    'module' => 'taxonomy',
    'class' => 'RulesTaxonomyEventHandler',
  );

  return array(
    'taxonomy_term_view' => $defaults_term + array(
        'label' => t('After viewing a term'),
        'variables' => array(
          'term' => array('type' => 'taxonomy_term', 'label' => t('Viewed term')),
        ),
      ),
  );
}

/**
 * Implements hook_entity_view().
 */
function modulename_entity_view($entity, $type, $view_mode, $langcode) {
  switch ($type) {
    case 'taxonomy_term':
      rules_invoke_event('taxonomy_term_view--' . $entity->vocabulary_machine_name, $entity);
      rules_invoke_event('taxonomy_term_view', $entity, $view_mode);
      break;
  }
}
Kojo Unsui’s picture

Status: Active » Fixed
phily’s picture

#5 seems to be working good.
Thanks Kojo Unsui.

Status: Fixed » Closed (fixed)

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