- 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') {
+ $tagParams = array(
+ 'name' => $tagValue[0],
+ 'parent_id' => $parentId,
+ );
+ $tagObject = CRM_Core_BAO_Tag::add($tagParams, CRM_Core_DAO::$_nullArray);
+ $tagId = $tagObject->id;