You are here

function term_merge_add_entity_as_synonym in Term Merge 7

Allow to merge $synonym_entity as a synonym into $trunk_entity.

Helpful function during various merging operations. It allows you to add a synonym (where possible) into one entity, which will represent another entity in the format expected by the field in which the synonym is being added.

Parameters

object $trunk_entity: Fully loaded entity object in which the synonym is being added

string $trunk_entity_type: Entity type of $trunk_entity

string $behavior_provider: Machine name of behavior implementation into which the synonym entity should be merged

object $synonym_entity: Fully loaded entity object which will be added as a synonym

string $synonym_entity_type: Entity type of $synonym_entity

Return value

bool Whether synonym has been successfully added

1 call to term_merge_add_entity_as_synonym()
term_merge_action in ./term_merge.module
Action function. Perform action "Term Merge".

File

./term_merge.module, line 888
Provide functionality for merging taxonomy terms one into another.

Code

function term_merge_add_entity_as_synonym($trunk_entity, $trunk_entity_type, $behavior_provider, $synonym_entity, $synonym_entity_type) {
  if ($trunk_entity_type != 'taxonomy_term') {

    // So far we only work with taxonomy terms.
    return FALSE;
  }
  $bundle = entity_extract_ids($trunk_entity_type, $trunk_entity);
  $bundle = $bundle[2];
  $behavior_implementations = synonyms_behavior_get_all_enabled($trunk_entity_type, $bundle, $behavior_provider);
  foreach ($behavior_implementations as $behavior_implementation) {
    if ($behavior_implementation['behavior'] == 'term_merge') {
      $behavior_implementation['object']
        ->mergeTerm($trunk_entity, $synonym_entity, $synonym_entity_type);
      taxonomy_term_save($trunk_entity);
      return TRUE;
    }
  }
  return FALSE;
}