diff --git a/CRM/Tag/Form/Edit.php b/CRM/Tag/Form/Edit.php
index 8d6d94ff678f..6def792c3428 100644
--- a/CRM/Tag/Form/Edit.php
+++ b/CRM/Tag/Form/Edit.php
@@ -58,6 +58,9 @@ public function buildQuickForm() {
}
}
else {
+ $parentId = NULL;
+ $isTagsetChild = FALSE;
+
$this->_isTagSet = CRM_Utils_Request::retrieve('tagset', 'Positive', $this);
if (!$this->_isTagSet &&
@@ -67,9 +70,16 @@ public function buildQuickForm() {
$this->_isTagSet = TRUE;
}
+ if ($this->_id) {
+ $parentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'parent_id');
+ $isTagSetChild = $parentId ? CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $parentId, 'is_tagset') : FALSE;
+ }
+
if (!$this->_isTagSet) {
- $colorTags = CRM_Core_BAO_Tag::getColorTags(NULL, TRUE, $this->_id);
- $this->add('select2', 'parent_id', ts('Parent Tag'), $colorTags, FALSE, array('placeholder' => ts('- select -')));
+ if (!$isTagSetChild) {
+ $colorTags = CRM_Core_BAO_Tag::getColorTags(NULL, TRUE, $this->_id);
+ $this->add('select2', 'parent_id', ts('Parent Tag'), $colorTags, FALSE, array('placeholder' => ts('- select -')));
+ }
// Tagsets are not selectable by definition so only include the selectable field if NOT a tagset.
$selectable = $this->add('checkbox', 'is_selectable', ts('Selectable?'));
@@ -99,13 +109,7 @@ public function buildQuickForm() {
$isReserved = $this->add('checkbox', 'is_reserved', ts('Reserved?'));
- $usedFor = $this->addSelect('used_for', array('multiple' => TRUE, 'option_url' => NULL));
-
- if ($this->_id &&
- CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'parent_id')
- ) {
- $usedFor->freeze();
- }
+ $this->addSelect('used_for', array('multiple' => TRUE, 'option_url' => NULL));
$adminTagset = TRUE;
if (!CRM_Core_Permission::check('administer Tagsets')) {
@@ -129,7 +133,7 @@ public function setDefaultValues() {
if (empty($this->_id) || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'color')) {
$defaults['color'] = '#ffffff';
}
- if (empty($this->_id) && $this->_isTagSet) {
+ if (empty($this->_id)) {
$defaults['used_for'] = 'civicrm_contact';
}
return $defaults;
diff --git a/CRM/Tag/Page/Tag.php b/CRM/Tag/Page/Tag.php
index cd02704792fb..42327a960bcd 100644
--- a/CRM/Tag/Page/Tag.php
+++ b/CRM/Tag/Page/Tag.php
@@ -164,10 +164,12 @@ public function browse($action = NULL, $sort = NULL) {
$usedFor = CRM_Core_OptionGroup::values('tag_used_for');
- $query = "SELECT t1.name, t1.id, t2.name as parent, t1.description, t1.used_for, t1.is_tagset,
- t1.is_reserved, t1.parent_id, t1.used_for, t1.color
- FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id
- GROUP BY t1.parent_id, t1.id";
+ $query = " SELECT t1.name, t1.id, t2.name as parent, t1.description, t1.used_for, t1.is_tagset as is_tagset,
+ t1.is_reserved, t1.parent_id, t1.used_for, t1.color, t2.is_tagset as is_tagset_child, t2.parent_id as grandparent_id
+ FROM civicrm_tag t1
+ LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id
+ LEFT JOIN civicrm_tag t3 ON t2.parent_id = t3.id
+ ORDER BY CONCAT(IFNULL(t3.name, ''), IFNULL(t2.name, ''), t1.name)";
$tag = CRM_Core_DAO::executeQuery($query);
$values = array();
@@ -186,9 +188,7 @@ public function browse($action = NULL, $sort = NULL) {
}
}
- if (!empty($used)) {
- $values[$tag->id]['used_for'] = implode(", ", $used);
- }
+ $values[$tag->id]['used_for'] = implode(", ", $used);
$newAction = $action;
if ($values[$tag->id]['is_reserved']) {
diff --git a/templates/CRM/Tag/Form/Edit.tpl b/templates/CRM/Tag/Form/Edit.tpl
index 4d982a765e48..46dc9725cdca 100644
--- a/templates/CRM/Tag/Form/Edit.tpl
+++ b/templates/CRM/Tag/Form/Edit.tpl
@@ -85,3 +85,17 @@
{/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}
+{literal}
+
+{/literal}
\ No newline at end of file
diff --git a/templates/CRM/Tag/Page/Tag.tpl b/templates/CRM/Tag/Page/Tag.tpl
index 5eb43910a10d..c0f418b394b4 100644
--- a/templates/CRM/Tag/Page/Tag.tpl
+++ b/templates/CRM/Tag/Page/Tag.tpl
@@ -27,146 +27,200 @@
{capture assign=docLink}{docURL page="user/organising-your-data/groups-and-tags"}{/capture}
{if $action eq 1 or $action eq 2 or $action eq 8}
- {include file="CRM/Tag/Form/Edit.tpl"}
+ {include file="CRM/Tag/Form/Edit.tpl"}
{else}
-
+
- {ts 1=$docLink}Tags can be assigned to any contact record, and are a convenient way to find contacts. You can create as many tags as needed to organize and segment your records.{/ts} {$docLink}
+ {ts 1=$docLink}Tags can be assigned to any contact record, and are a convenient way to find contacts. You can create as many tags as needed to organize and segment your records.{/ts} {$docLink}
{if $rows}
- {if !($action eq 1 and $action eq 2)}
+
+
+
- {/if}
-
- {include file="CRM/common/jsortable.tpl"}
-
-
- {strip}
-
+ {/if}
+ {strip}
+
- {/strip}
+ {/strip}
- {if !($action eq 1 and $action eq 2)}
+
+
+ {if !($action eq 1 and $action eq 2)}
+
+ {/if}
+
+ {include file="CRM/common/jsortable.tpl"}
{else}
-
{/if}
-
+
{literal}
-
+ });
+
+
{/literal}
{/if}