Skip to content

Commit

Permalink
fixes #1 and #2 for CRM-14052
Browse files Browse the repository at this point in the history
----------------------------------------
* CRM-14052: Tagset fixes
  http://issues.civicrm.org/jira/browse/CRM-14052
  • Loading branch information
kurund committed Jan 6, 2014
1 parent 94a7361 commit 0cc0faa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Edit/TagsAndGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
27 changes: 20 additions & 7 deletions CRM/Core/Form/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)) {
Expand Down

0 comments on commit 0cc0faa

Please sign in to comment.