diff --git a/CRM/Contact/Form/Edit/TagsAndGroups.php b/CRM/Contact/Form/Edit/TagsAndGroups.php index 2799b0b88..2f3f73339 100644 --- a/CRM/Contact/Form/Edit/TagsAndGroups.php +++ b/CRM/Contact/Form/Edit/TagsAndGroups.php @@ -162,7 +162,7 @@ static function buildQuickForm(&$form, // build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); - CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE); + CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, TRUE, TRUE); } $form->assign('tagGroup', $form->_tagGroup); } diff --git a/CRM/Core/Form/Tag.php b/CRM/Core/Form/Tag.php index f408167d2..5a59581b5 100644 --- a/CRM/Core/Form/Tag.php +++ b/CRM/Core/Form/Tag.php @@ -236,7 +236,7 @@ static function buildQuickForm(&$form, $parentNames, $entityTable, $entityId = N * */ static function postProcess(&$params, $entityId, $entityTable = 'civicrm_contact', &$form) { - foreach ($params as $value) { + foreach ($params as $parentId => $value) { if (!$value) { continue; } @@ -245,14 +245,27 @@ static function postProcess(&$params, $entityId, $entityTable = 'civicrm_contact $insertSQL = NULL; if (!empty($tagsIDs)) { foreach ($tagsIDs as $tagId) { - if (is_numeric($tagId)) { - if ($form && $form->_action != CRM_Core_Action::UPDATE) { - $insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) "; - } - elseif (!$form || !array_key_exists($tagId, $form->_entityTagValues)) { - $insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) "; + if (!is_numeric($tagId)) { + // check if user has selected existing tag or is creating new tag + // this is done to allow numeric tags etc. + $tagValue = explode(':::', $tagId); + + if (isset($tagValue[1]) && $tagValue[1] == 'value') { + $params = array( + 'name' => $tagValue[0], + 'parent_id' => $parentId, + ); + $tagObject = CRM_Core_BAO_Tag::add($params, CRM_Core_DAO::$_nullArray); + $tagId = $tagObject->id; } } + + if ($form && $form->_action != CRM_Core_Action::UPDATE) { + $insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) "; + } + elseif (!$form || !array_key_exists($tagId, $form->_entityTagValues)) { + $insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) "; + } } if (!empty($insertValues)) {