You are here

function community_tags_node_community_tags_tags_added in Community Tags 6.2

Implementation of hook_community_tags_tags_added(). Implement this rather than hook_community_tags_tag() as we only want to do this when a tag is actually added.

Apply node term synchronisation of added tags. @todo - add options to syncronisation - e.g. if role x tags then make it a node term

File

community_tags_node/community_tags_node.module, line 155
community_tags_node.module

Code

function community_tags_node_community_tags_tags_added($node, $user, $tags) {
  static $node_to_save;
  if (!_community_tags_node_is_processing()) {

    // make sure we got the latest node
    if (!$node_to_save) {
      $node_to_save = _community_tags_get_node($node->nid);
    }

    // add new tags
    foreach ($tags as $tid => $tag) {

      // if tags are synched with node terms and this tag isn't a node term - then add it to node terms
      if (!isset($node_to_save->taxonomy[$tid]) && (_community_tags_node_is_opmode(COMMUNITY_TAGS_NODE_OPMODE_SYNC_CT_TO_NT, $tag->vid, $node->type) || _community_tags_node_is_editor_tag($node, $user, $tag))) {
        $node_to_save->taxonomy[$tid] = $tag;
        $node_save_required = TRUE;
      }
    }
    if ($node_save_required) {

      // setting this will prevent full CT node update processing
      $node_to_save->community_tags_op = TRUE;

      // invoke full node save pipeline - term nodes will be updated, and good stuff like search (including the Apache SOLR Integration module) will know about it.
      _community_tags_node_save($node_to_save);
    }
  }
}