From: Coleman Watts Date: Tue, 29 Apr 2014 17:39:39 +0000 (-0700) Subject: CRM-13966 - Switch to entityRef for tags X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6d538af3d4e965c20bfb77e7d83c9c5642d6c634;p=civicrm-core.git CRM-13966 - Switch to entityRef for tags --- diff --git a/CRM/Core/Form/Tag.php b/CRM/Core/Form/Tag.php index 36906cc31d..05adaefbe5 100644 --- a/CRM/Core/Form/Tag.php +++ b/CRM/Core/Form/Tag.php @@ -43,7 +43,7 @@ class CRM_Core_Form_Tag { /** * Function to build tag widget if correct parent is passed * - * @param object $form form object + * @param CRM_Core_Form $form form object * @param string $parentName parent name ( tag name) * @param string $entityTable entitytable 'eg: civicrm_contact' * @param int $entityId entityid 'eg: contact id' @@ -109,7 +109,12 @@ class CRM_Core_Form_Tag { $tagset[$tagsetItem]['tagsetElementName'] = $tagsetElementName; if ($tagsetElementName) { - $form->add('text', "{$tagsetElementName}[{$parentId}]", NULL); + $form->addEntityRef("{$tagsetElementName}[{$parentId}]", NULL, array( + 'entity' => 'tag', + 'multiple' => TRUE, + 'create' => TRUE, + 'api' => array('params' => array('parent_id' => $parentId))) + ); } if ($entityId) { @@ -223,7 +228,9 @@ class CRM_Core_Form_Tag { // assign current tagsets which is used in postProcess $form->_tagsetInfo = $tagset; $form->assign("tagsetType", $mode); - $form->assign("tagsetInfo_$mode", $tagset); + $tagsetInfo = (array) $form->get_template_vars("tagsetInfo"); + $tagsetInfo[$mode] = $tagset; + $form->assign("tagsetInfo", $tagsetInfo); $form->assign("isTagset", TRUE); } } diff --git a/templates/CRM/Activity/Form/Activity.tpl b/templates/CRM/Activity/Form/Activity.tpl index c6c529de2a..4027948003 100644 --- a/templates/CRM/Activity/Form/Activity.tpl +++ b/templates/CRM/Activity/Form/Activity.tpl @@ -180,7 +180,7 @@ {/if} {if $tagsetInfo_activity} - {include file="CRM/common/Tag.tpl" tagsetType='activity'} + {include file="CRM/common/Tagset.tpl" tagsetType='activity'} {/if} {if $action neq 4 OR $viewCustomData} diff --git a/templates/CRM/Activity/Form/Search/Common.tpl b/templates/CRM/Activity/Form/Search/Common.tpl index 4844599817..a57f258608 100644 --- a/templates/CRM/Activity/Form/Search/Common.tpl +++ b/templates/CRM/Activity/Form/Search/Common.tpl @@ -105,11 +105,11 @@
{$form.activity_result.html} - {include file="CRM/common/Tag.tpl" tagsetType='activity'} + {include file="CRM/common/Tagset.tpl" tagsetType='activity'} {else} - {include file="CRM/common/Tag.tpl" tagsetType='activity'} + {include file="CRM/common/Tagset.tpl" tagsetType='activity'} {/if} diff --git a/templates/CRM/Activity/Form/Task/AddToTag.tpl b/templates/CRM/Activity/Form/Task/AddToTag.tpl index 5b2894d93d..5597c2cb66 100644 --- a/templates/CRM/Activity/Form/Task/AddToTag.tpl +++ b/templates/CRM/Activity/Form/Task/AddToTag.tpl @@ -42,7 +42,7 @@ - {include file="CRM/common/Tag.tpl"} + {include file="CRM/common/Tagset.tpl"} diff --git a/templates/CRM/Activity/Form/Task/RemoveFromTag.tpl b/templates/CRM/Activity/Form/Task/RemoveFromTag.tpl index 9882c801e9..55d2e8a2d7 100644 --- a/templates/CRM/Activity/Form/Task/RemoveFromTag.tpl +++ b/templates/CRM/Activity/Form/Task/RemoveFromTag.tpl @@ -42,7 +42,7 @@ - {include file="CRM/common/Tag.tpl"} + {include file="CRM/common/Tagset.tpl"} diff --git a/templates/CRM/Case/Form/Activity.tpl b/templates/CRM/Case/Form/Activity.tpl index 7019686c90..4e27e8e99c 100644 --- a/templates/CRM/Case/Form/Activity.tpl +++ b/templates/CRM/Case/Form/Activity.tpl @@ -273,7 +273,7 @@ {/if} - {include file="CRM/common/Tag.tpl" tagsetType='activity'} + {include file="CRM/common/Tagset.tpl" tagsetType='activity'} {/if} diff --git a/templates/CRM/Case/Form/Case.tpl b/templates/CRM/Case/Form/Case.tpl index 4147889e25..2edfc5e818 100644 --- a/templates/CRM/Case/Form/Case.tpl +++ b/templates/CRM/Case/Form/Case.tpl @@ -123,7 +123,7 @@ -{include file="CRM/common/Tag.tpl" tagsetType='case'} +{include file="CRM/common/Tagset.tpl" tagsetType='case'} {/if} diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index 97be9a3255..af81584988 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -440,7 +440,7 @@ {assign var="tagExits" value=1} {/if} - {foreach from=$tagsetInfo_case item=displayTagset} + {foreach from=$tagsetInfo.case item=displayTagset} {if $displayTagset.entityTagsArray}
  {$displayTagset.parentName}: @@ -469,7 +469,7 @@
{$form.case_tag.label}
{$form.case_tag.html}

-
{include file="CRM/common/Tag.tpl" tagsetType='case'}
+
{include file="CRM/common/Tagset.tpl" tagsetType='case'}

diff --git a/templates/CRM/Case/Form/Search/Common.tpl b/templates/CRM/Case/Form/Search/Common.tpl index b84ef3396b..7a1fd34319 100644 --- a/templates/CRM/Case/Form/Search/Common.tpl +++ b/templates/CRM/Case/Form/Search/Common.tpl @@ -77,7 +77,7 @@ {/if} -{include file="CRM/common/Tag.tpl" tagsetType='case'} +{include file="CRM/common/Tagset.tpl" tagsetType='case'} {if $caseGroupTree} diff --git a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl index 944d34d0aa..7db44d910a 100644 --- a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl +++ b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl @@ -62,7 +62,7 @@ {/foreach} {if !$type || $type eq 'tag'} - {include file="CRM/common/Tag.tpl"} + {include file="CRM/common/Tagset.tpl"} {/if} {if $title} diff --git a/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl b/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl index 6b32376c00..e4664a1e43 100644 --- a/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl +++ b/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl @@ -121,7 +121,7 @@   {/if} {if $isTagset} - {include file="CRM/common/Tag.tpl"} + {include file="CRM/common/Tagset.tpl"} {/if} {$form.tag_search.label} {help id="id-all-tags"}
{$form.tag_search.html} {if ! $isTagset} diff --git a/templates/CRM/Contact/Form/Task/AddToTag.tpl b/templates/CRM/Contact/Form/Task/AddToTag.tpl index 0ef8732136..c4fe1ec2f3 100644 --- a/templates/CRM/Contact/Form/Task/AddToTag.tpl +++ b/templates/CRM/Contact/Form/Task/AddToTag.tpl @@ -42,7 +42,7 @@ - {include file="CRM/common/Tag.tpl"} + {include file="CRM/common/Tagset.tpl"} diff --git a/templates/CRM/Contact/Form/Task/RemoveFromTag.tpl b/templates/CRM/Contact/Form/Task/RemoveFromTag.tpl index ff9a32d599..747043c239 100644 --- a/templates/CRM/Contact/Form/Task/RemoveFromTag.tpl +++ b/templates/CRM/Contact/Form/Task/RemoveFromTag.tpl @@ -43,7 +43,7 @@ - {include file="CRM/common/Tag.tpl"} + {include file="CRM/common/Tagset.tpl"} diff --git a/templates/CRM/Form/attachment.tpl b/templates/CRM/Form/attachment.tpl index 97640108f5..9a5877baa4 100644 --- a/templates/CRM/Form/attachment.tpl +++ b/templates/CRM/Form/attachment.tpl @@ -73,8 +73,8 @@
{$form.tag_1.html}
{/if} - {if $tagsetInfo_attachment} - {include file="CRM/common/Tag.tpl" tagsetType='attachment' tagsetNumber=1 } + {if $tagsetInfo.attachment} + {include file="CRM/common/Tagset.tpl" tagsetType='attachment' tagsetNumber=1 } {/if} {section name=attachLoop start=2 loop=$numAttachments+1} {assign var=index value=$smarty.section.attachLoop.index} @@ -90,8 +90,8 @@
{$form.$tagElement.html}
- {if $tagsetInfo_attachment} - {include file="CRM/common/Tag.tpl" tagsetType='attachment' tagsetNumber=$index} + {if $tagsetInfo.attachment} + {include file="CRM/common/Tagset.tpl" tagsetType='attachment' tagsetNumber=$index} {/if} {/section} diff --git a/templates/CRM/Tag/Form/Tag.tpl b/templates/CRM/Tag/Form/Tag.tpl index dd6fe06e9b..94f5750e82 100644 --- a/templates/CRM/Tag/Form/Tag.tpl +++ b/templates/CRM/Tag/Form/Tag.tpl @@ -110,5 +110,5 @@

-{include file="CRM/common/Tag.tpl" context="contactTab"} +{include file="CRM/common/Tagset.tpl" context="contactTab"} diff --git a/templates/CRM/common/Tagset.tpl b/templates/CRM/common/Tagset.tpl new file mode 100644 index 0000000000..8d19c9a2b3 --- /dev/null +++ b/templates/CRM/common/Tagset.tpl @@ -0,0 +1,45 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.5 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2014 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} +{if empty($tagsetType)} + {capture assign="tagsetType"}contact{/capture} +{/if} +{foreach from=$tagsetInfo.$tagsetType item=tagset} +
+ +
+ {assign var=elemName value = $tagset.tagsetElementName} + {assign var=parID value = $tagset.parentID} + {assign var=editTagSet value=false} + {$form.$elemName.$parID.html} + {if $action ne 4 } + {assign var=editTagSet value=true} + {if $action eq 16 and !($permission eq 'edit') } + {assign var=editTagSet value=false} + {/if} + {/if} +
+
+{/foreach}