if (!is_numeric($tagID)) {
$tagID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagID, 'id', 'name');
}
- if ($entityId) {
+ if (!$skipEntityAction && $entityId) {
// delete this tag entry for the entity
$params = array(
'entity_table' => $entityTable,
*
*/
static function postProcess(&$params, $entityId, $entityTable = 'civicrm_contact', &$form) {
+ $allTagIds = array();
foreach ($params as $parentId => $value) {
if (!$value) {
continue;
}
}
+ $allTagIds[] = $tagId;
if ($form && $form->_action != CRM_Core_Action::UPDATE) {
$insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) ";
}
}
}
}
+
+ // delete tags that are missing
+ if (!empty($allTagIds)) {
+ $validTagIds = implode(',', $allTagIds);
+ $deleteSQL = "DELETE FROM civicrm_entity_tag WHERE entity_id={$entityId} AND entity_table='{$entityTable}'
+ AND tag_id NOT IN ({$validTagIds})";
+ CRM_Core_DAO::executeQuery($deleteSQL);
+ }
}
}
setVal[x] = valArray[x];
}
}
- CRM.alert('', '{/literal}{ts escape='js'}Removed{/ts}{literal}', 'success');
+ if (!skipEntityAction) {
+ CRM.alert('', '{/literal}{ts escape='js'}Removed{/ts}{literal}', 'success');
+ }
}
else {
CRM.alert('', '{/literal}{ts escape='js'}Saved{/ts}{literal}', 'success');