I have taxonomy spaces set up, and have tagged a node with a term from the spaces_taxonomy enabled vocabulary. However, when viewing this node, the relevant taxonomy space is not activated. Attached patch resolves for me. With this applied, the space is correctly activated when viewing the node.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrfelton’s picture

Status: Active » Needs review
FileSize
868 bytes
chriz001’s picture

I had the same problem, however your code didn't work for me.. but i noticed your loading the space based on the object nid.

I changed that to load the space based on the tid associated with that node.

Seems to work for me.

/**
 * Implements of hook_spaces_get_space_from_object().
 */
function spaces_taxonomy_spaces_get_space_from_object($type, $object) {
  if ($type == 'node') {
    $vocab = variable_get('spaces_taxonomy_machine_name', 0);
    $fields = field_info_fields();
    foreach ($fields as $name => $field) {
      if ($field['type'] == 'taxonomy_term_reference' && $vocab == $field['settings']['allowed_values'][0]['vocabulary']) {
        $term = $object->$name;
        return spaces_load('taxonomy', $term['und'][0]['tid']);
      }
    }
  }
}
q0rban’s picture

Title: spaces_taxonomy space not activated wen viewing node tagged with taxonomy space term » spaces_taxonomy space not activated when viewing node tagged with taxonomy space term
Priority: Normal » Major
FileSize
1.07 KB
1.65 KB

Marking as major, since this module doesn't even work without this functionality.

Attached patches for 7.x and 6.x. One thing to note on the 7.x patch. I see no reason to check for $type == 'node' anymore, as taxonomy can exist on other entities in 7. If someone disagrees, let me know and I can re-roll.

chriz001’s picture

Looks good to me.

Quick question, should we use $object->language instead of LANGUAGE_NONE when we load the space?
they both return 'und' if there is no language.

Im not sure, maybe it doesn't matter :)

Finn Lewis’s picture

Patch http://drupal.org/files/spaces_taxonomy-1404586-return-taxonomy-space-3.... in #3 works for me.
But I agree with @chriz001 about the language issue - presumably using LANGUAGE_NONE would prevent this working muli-language content.

euk’s picture

Issue summary: View changes

+1
Patch https://www.drupal.org/files/spaces_taxonomy-1404586-return-taxonomy-spa... in #3 works for me as well.
Using:
- Drupal v7.28
- Spaces 7.x-3.0-alpha1

However, if you look at the spaces_taxonomy class (spaces_taxonomy.inc), there is a method space_taxonomy::router, which has very similar piece of code:

/**
  * Override of router().
  */
  function router($op, $object = NULL) {
    switch ($op) {
      case 'init':
        // NOTE: in D6 this used to handle multiple terms via taxonomy_terms_parse_string
        // but in D7 that has gone away for taxonomy term pages
        if (implode('/', array(arg(0), arg(1))) === 'taxonomy/term' && arg(2)) {
          $tid = arg(2);
          if ($term = taxonomy_term_load($tid)) {
            $this->router_term($term);
          }
        }
        break;
      case 'node':
        $node = $object;
        $vocab = variable_get('spaces_taxonomy_machine_name', 0);
        $fields = field_info_fields();
        foreach ($fields as $name => $field) {
          if ($field['type'] == 'taxonomy_term_reference' && $vocab == $field['settings']['allowed_values'][0]['vocabulary']) {
            $term = isset($node->{$name}['und'][0]['taxonomy_term'])
                        ? $node->{$name}['und'][0]['taxonomy_term']
                        : taxonomy_term_load($node->{$name}['und'][0]['tid']);
            if ($term) {
              $this->router_term($term);
              return;
            }
          }
        }
        break;
    }
    return;
  }

I wonder if this method was supposed to switch spaces?

$op='init' is passed when viewing taxonomy. It switches spaces when navigating to something like 'taxonomy/term/56'

$op='node' seems to be never passed to the method.

Cheers!