You are here

function _hashtags_index_sync_tags in Hashtags 7

Syncronize tags from 'hashtags_index' to field_hashtags. Must be called inside hook_entity_presave()

Parameters

EntityMetadataWrapper &$wrapper Wrapper of current entity (node):

array $tags list of tags that should be syncronizied : with field_hashtags

Return value

boolean

2 calls to _hashtags_index_sync_tags()
hashtags_comment_presave in ./hashtags.module
Implements hook_comment_presave().
hashtags_entity_presave in ./hashtags.module
Implementation of hook_entity_presave().

File

./hashtags.module, line 655

Code

function _hashtags_index_sync_tags(&$wrapper, $entity_type, $save = FALSE, $field_name = "field_hashtags", $tags = array()) {
  if (!sizeof($tags)) {
    $entity_id = $wrapper
      ->getIdentifier();
    $tags = _hashtags_index_get_all_tags($entity_id, $entity_type);
  }

  // attach all current term tids to hashtags field
  $wrapper->{$field_name}
    ->set(array_values($tags));

  // need to be saved (used called from hook_comment_insert
  // to update a node). Don't need to be used when it's called
  // from hook_entity_presave()
  if ($save) {
    $wrapper
      ->save();
  }
  return TRUE;
}