I'm trying to use Taxonomy Manager and Node Auto Term (NAT) and my site having the whole packet of Domain Access, but it seems to have some issues.

I can see with Devel module that the Update query is executing, but i guess it's passing the wrong parameters, so when i create terms with either both modules, it doesn't create the record at domain_taxonomy_access.

What i see is... both modules call taxonomy_save_term, but they don't call domain_taxonomy_save_term or update term, anything.

I'm not a PHP coder, but i believe that when they call for taxonomy_save_term, the function for Domain Taxonomy for save, update or create term should be called too, or maybe it's called but the parameters are not passing correctly.

So, after i create a term with Taxonomy Manager or Node Auto Term (NAT), i have to goto Taxonomy admin and edit the term so Domain Taxonomy could create the records in the needed tables.

Is there any posibility to make this works?

Comments

dunx’s picture

There may be a "proper" way of doing this, so that DT's save_term function is called automatically, but I couldn't find one.

I ended up doing some work in my module of the data required for the DT access and grants and then called the DT function directly. I guess other modules that are also creating terms would need to do something similar to be DT compatible.

My use case is creating Brands as Taxonomy terms during the loading of an XML data feed. This function gets the current tid for the brand or creates a new term (core and DT), before returning the tid.

function affshop_get_brand($brand) {

  static $brand_tids = array();
  $vid = 15; // That's my brand vocab id.

  if ( ! $brand ) return;

  if ( $brand_ids[$brand] ) {
    return $brand_ids[$brand];
  }

  /* Function will return array of objects for each matching term regardless of vocab,
   * so we need to make sure we get the term for our brand vocab.
   */
  $terms = taxonomy_get_term_by_name($brand);
  foreach ($terms as $vidterm) {
    if ( $vidterm->vid == $vid ) {
      $term = $vidterm;  // Object.
      break;
    }
  }
  if ( ! $term ) {
    // Create new term.
    $term = array(
      'vid' => $vid,
      'name' => $brand,
      'domain_update_subterm' => 0,
      'domain_update_subnodes' => 0,
      'domain_load_fromparent' => 1,
      'domain_site' => 1,
      'domains' => array( -1 => -1, 2 => 0, 5 => 0, 3 => 0, 4 => 0, 6 => 0), // My domains.
      'domain_source' => 0,
    );
    taxonomy_save_term($term); // Expects an array. Will update $term with new tid.
    $term = (object) $term; // Next function needs object, We also return $term->tid, not $term['tid']
    domain_taxonomy_save_term($term); // Expects an object.
  }

  // Save brand's tid.
  $brand_tids[$brand] = $term->tid;

  // Return existing or new term id.
  return $term->tid;

}

I hope that's of some use to somebody.