From: colemanw Date: Sat, 7 Oct 2023 21:02:28 +0000 (-0400) Subject: Tag - Add label field X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=bcf668dc2f635985513ecd7f18562dc1c23eee54;p=civicrm-core.git Tag - Add label field --- diff --git a/CRM/Admin/Page/AJAX.php b/CRM/Admin/Page/AJAX.php index 0cc9bbbb8c..c82be9ba8d 100644 --- a/CRM/Admin/Page/AJAX.php +++ b/CRM/Admin/Page/AJAX.php @@ -290,7 +290,7 @@ class CRM_Admin_Page_AJAX { $result = []; $whereClauses = ['is_tagset <> 1']; - $orderColumn = 'name'; + $orderColumn = 'label'; // fetch all child tags in Array('parent_tag' => array('child_tag_1', 'child_tag_2', ...)) format $childTagIDs = CRM_Core_BAO_Tag::getChildTags($substring); @@ -300,7 +300,7 @@ class CRM_Admin_Page_AJAX { $whereClauses[] = "parent_id = $parent"; } elseif ($substring) { - $whereClauses['substring'] = " name LIKE '%$substring%' "; + $whereClauses['substring'] = " label LIKE '%$substring%' "; if (!empty($parentIDs)) { $whereClauses['substring'] = sprintf(" %s OR id IN (%s) ", $whereClauses['substring'], implode(',', $parentIDs)); } @@ -328,7 +328,7 @@ class CRM_Admin_Page_AJAX { $usedFor = (array) explode(',', $dao->used_for); $tag = [ 'id' => $dao->id, - 'text' => $dao->name, + 'text' => $dao->label, 'a_attr' => [ 'class' => 'crm-tag-item', ], diff --git a/CRM/Core/BAO/EntityTag.php b/CRM/Core/BAO/EntityTag.php index c48246775d..97c94866d9 100644 --- a/CRM/Core/BAO/EntityTag.php +++ b/CRM/Core/BAO/EntityTag.php @@ -301,7 +301,7 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { public static function getContactTags($contactID, $count = FALSE) { $contactTags = []; if (!$count) { - $select = "SELECT ct.id, ct.name "; + $select = "SELECT ct.id, ct.label "; } else { $select = "SELECT count(*) as cnt"; @@ -322,7 +322,7 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag { } while ($dao->fetch()) { - $contactTags[$dao->id] = $dao->name; + $contactTags[$dao->id] = $dao->label; } return $contactTags; diff --git a/CRM/Core/BAO/Tag.php b/CRM/Core/BAO/Tag.php index cd2a0522e0..a86f4b1785 100644 --- a/CRM/Core/BAO/Tag.php +++ b/CRM/Core/BAO/Tag.php @@ -311,7 +311,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { 'sort' => "name ASC", ], 'is_tagset' => 0, - 'return' => ['name', 'description', 'parent_id', 'color', 'is_selectable', 'used_for'], + 'return' => ['label', 'description', 'parent_id', 'color', 'is_selectable', 'used_for'], ]; if ($usedFor) { $params['used_for'] = ['LIKE' => "%$usedFor%"]; @@ -322,7 +322,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { $allTags = []; foreach (CRM_Utils_Array::value('values', civicrm_api3('Tag', 'get', $params)) as $id => $tag) { $allTags[$id] = [ - 'text' => $tag['name'], + 'text' => $tag['label'], 'id' => $id, 'description' => $tag['description'] ?? NULL, 'parent_id' => $tag['parent_id'] ?? NULL, @@ -366,8 +366,16 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { */ public static function add(&$params, $ids = []) { $id = $params['id'] ?? $ids['tag'] ?? NULL; - if (!$id && !self::dataExists($params)) { - return NULL; + if (!$id) { + // Make label from name if missing. + if (CRM_Utils_System::isNull($params['label'] ?? NULL)) { + // If name is also missing, cannot create object. + if (CRM_Utils_System::isNull($params['name'] ?? NULL)) { + // FIXME: Throw exception + return NULL; + } + $params['label'] = $params['name']; + } } // Check permission to create or modify reserved tag @@ -401,7 +409,6 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { // save creator id and time if (!$id) { $params['created_id'] = $params['created_id'] ?? CRM_Core_Session::getLoggedInContactID(); - $params['created_date'] = $params['created_date'] ?? date('YmdHis'); } $tag = self::writeRecord($params); @@ -422,23 +429,6 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { return $tag; } - /** - * Check if there is data to create the object. - * - * @param array $params - * - * @return bool - */ - public static function dataExists($params) { - // Disallow empty values except for the number zero. - // TODO: create a utility for this since it's needed in many places - if (!empty($params['name']) || (string) $params['name'] === '0') { - return TRUE; - } - - return FALSE; - } - /** * Get the tag sets for a entity object. * @@ -450,7 +440,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { */ public static function getTagSet($entityTable) { $tagSets = []; - $query = "SELECT name, id FROM civicrm_tag + $query = "SELECT label, id FROM civicrm_tag WHERE is_tagset=1 AND parent_id IS NULL and used_for LIKE %1"; $dao = CRM_Core_DAO::executeQuery($query, [ 1 => [ @@ -459,7 +449,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { ], ], TRUE, NULL, FALSE, FALSE); while ($dao->fetch()) { - $tagSets[$dao->id] = $dao->name; + $tagSets[$dao->id] = $dao->label; } return $tagSets; } diff --git a/CRM/Core/DAO/EntityTag.php b/CRM/Core/DAO/EntityTag.php index 3f57d572bd..df3e79bd2a 100644 --- a/CRM/Core/DAO/EntityTag.php +++ b/CRM/Core/DAO/EntityTag.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/EntityTag.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:2fccc138a26fe391325fd641c891cd91) + * (GenCodeChecksum:5bca5ff1c4ba7d85034410408464f0ac) */ /** @@ -200,7 +200,8 @@ class CRM_Core_DAO_EntityTag extends CRM_Core_DAO { 'pseudoconstant' => [ 'table' => 'civicrm_tag', 'keyColumn' => 'id', - 'labelColumn' => 'name', + 'labelColumn' => 'label', + 'nameColumn' => 'name', 'condition' => 'is_tagset != 1', ], 'add' => '1.1', diff --git a/CRM/Core/DAO/Tag.php b/CRM/Core/DAO/Tag.php index b84fa0d5e4..b6c5a2f1a4 100644 --- a/CRM/Core/DAO/Tag.php +++ b/CRM/Core/DAO/Tag.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/Tag.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:f8d8698f48fbd60b8d8e0bf8eff40c47) + * (GenCodeChecksum:ded9d6a9f9c08146a0205da83c838c91) */ /** @@ -35,7 +35,7 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { * * @var string */ - public static $_labelField = 'name'; + public static $_labelField = 'label'; /** * Should CiviCRM log any modifications to this table in the civicrm_log table. @@ -54,7 +54,7 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { public $id; /** - * Name of Tag. + * Unique machine name * * @var string * (SQL type: varchar(64)) @@ -62,6 +62,15 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { */ public $name; + /** + * User-facing tag name + * + * @var string + * (SQL type: varchar(64)) + * Note that values will be retrieved from the database as a string. + */ + public $label; + /** * Optional verbose description of the tag. * @@ -206,7 +215,7 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { 'name' => 'name', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Tag Name'), - 'description' => ts('Name of Tag.'), + 'description' => ts('Unique machine name'), 'required' => TRUE, 'maxlength' => 64, 'size' => CRM_Utils_Type::BIG, @@ -223,6 +232,30 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { 'localizable' => 0, 'add' => '1.1', ], + 'label' => [ + 'name' => 'label', + 'type' => CRM_Utils_Type::T_STRING, + 'title' => ts('Tag Label'), + 'description' => ts('User-facing tag name'), + 'required' => TRUE, + 'maxlength' => 64, + 'size' => CRM_Utils_Type::BIG, + 'usage' => [ + 'import' => FALSE, + 'export' => FALSE, + 'duplicate_matching' => FALSE, + 'token' => FALSE, + ], + 'where' => 'civicrm_tag.label', + 'table_name' => 'civicrm_tag', + 'entity' => 'Tag', + 'bao' => 'CRM_Core_BAO_Tag', + 'localizable' => 0, + 'html' => [ + 'type' => 'Text', + ], + 'add' => '5.68', + ], 'description' => [ 'name' => 'description', 'type' => CRM_Utils_Type::T_STRING, @@ -267,7 +300,8 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { 'pseudoconstant' => [ 'table' => 'civicrm_tag', 'keyColumn' => 'id', - 'labelColumn' => 'name', + 'labelColumn' => 'label', + 'nameColumn' => 'name', ], 'add' => '1.1', ], @@ -375,6 +409,7 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { 'localizable' => 0, 'FKClassName' => 'CRM_Contact_DAO_Contact', 'html' => [ + 'type' => 'EntityRef', 'label' => ts("Created By"), ], 'add' => '3.4', @@ -412,10 +447,17 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO { 'token' => FALSE, ], 'where' => 'civicrm_tag.created_date', + 'default' => 'CURRENT_TIMESTAMP', 'table_name' => 'civicrm_tag', 'entity' => 'Tag', 'bao' => 'CRM_Core_BAO_Tag', 'localizable' => 0, + 'html' => [ + 'type' => 'Select Date', + 'formatType' => 'activityDateTime', + 'label' => ts("Created Date"), + ], + 'readonly' => TRUE, 'add' => '3.4', ], ]; diff --git a/CRM/Tag/Form/Edit.php b/CRM/Tag/Form/Edit.php index 09d38c00f0..6fa36b90f2 100644 --- a/CRM/Tag/Form/Edit.php +++ b/CRM/Tag/Form/Edit.php @@ -102,13 +102,9 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form { $this->applyFilter('__ALL__', 'trim'); - $this->add('text', 'name', ts('Name'), - CRM_Core_DAO::getAttribute('CRM_Core_DAO_Tag', 'name'), TRUE + $this->add('text', 'label', ts('Label'), + CRM_Core_DAO::getAttribute('CRM_Core_DAO_Tag', 'label'), TRUE ); - $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', [ - 'CRM_Core_DAO_Tag', - $this->_id, - ]); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Tag', 'description') @@ -142,7 +138,7 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form { if (empty($this->_id) && $cloneFrom) { $params = ['id' => $cloneFrom]; CRM_Core_BAO_Tag::retrieve($params, $this->_values); - $this->_values['name'] .= ' (' . ts('copy') . ')'; + $this->_values['label'] .= ' (' . ts('copy') . ')'; if (!empty($this->_values['is_reserved']) && !CRM_Core_Permission::check('administer reserved tags')) { $this->_values['is_reserved'] = 0; } @@ -171,10 +167,10 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form { } if (count($this->_id) == 1 && $deleted == 1) { if ($tag['is_tagset']) { - CRM_Core_Session::setStatus(ts("The tag set '%1' has been deleted.", [1 => $tag['name']]), ts('Deleted'), 'success'); + CRM_Core_Session::setStatus(ts("The tag set '%1' has been deleted.", [1 => $tag['label']]), ts('Deleted'), 'success'); } else { - CRM_Core_Session::setStatus(ts("The tag '%1' has been deleted.", [1 => $tag['name']]), ts('Deleted'), 'success'); + CRM_Core_Session::setStatus(ts("The tag '%1' has been deleted.", [1 => $tag['label']]), ts('Deleted'), 'success'); } } else { @@ -211,7 +207,7 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form { $params['is_selectable'] = 0; } $tag = CRM_Core_BAO_Tag::add($params); - CRM_Core_Session::setStatus(ts("The tag '%1' has been saved.", [1 => $tag->name]), ts('Saved'), 'success'); + CRM_Core_Session::setStatus(ts("The tag '%1' has been saved.", [1 => $tag->label]), ts('Saved'), 'success'); $this->ajaxResponse['tag'] = $tag->toArray(); } CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/tag')); diff --git a/CRM/Tag/Page/Tag.php b/CRM/Tag/Page/Tag.php index 772439b7c4..6d4a26c694 100644 --- a/CRM/Tag/Page/Tag.php +++ b/CRM/Tag/Page/Tag.php @@ -40,7 +40,7 @@ class CRM_Tag_Page_Tag extends CRM_Core_Page { } $result = civicrm_api3('Tag', 'get', [ - 'return' => ["name", "used_for", "description", "created_id.display_name", "created_date", "is_reserved"], + 'return' => ["name", "label", "used_for", "description", "created_id.display_name", "created_date", "is_reserved"], 'is_tagset' => 1, 'options' => ['limit' => 0], ]); diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyEight.php b/CRM/Upgrade/Incremental/php/FiveSixtyEight.php index c974bd67be..66421e9435 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyEight.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyEight.php @@ -28,6 +28,10 @@ class CRM_Upgrade_Incremental_php_FiveSixtyEight extends CRM_Upgrade_Incremental * The version number matching this function name */ public function upgrade_5_68_alpha1($rev): void { + // Add column prior to updating it via runSql + $this->addTask('Add Tag.label field', 'addColumn', 'civicrm_tag', 'label', "varchar(64) NOT NULL COMMENT 'User-facing tag name' AFTER `name`"); + $this->addTask('Update Tag.name field', 'alterColumn', 'civicrm_tag', 'name', "varchar(64) NOT NULL COMMENT 'Unique machine name'"); + $this->addTask('Update Tag.created_date field', 'alterColumn', 'civicrm_tag', 'created_date', "datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time that tag was created.'"); $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); } diff --git a/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl index 4e284bc85b..9a2b0a2373 100644 --- a/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.68.alpha1.mysql.tpl @@ -1 +1,3 @@ {* file to handle db changes in 5.68.alpha1 during upgrade *} + +UPDATE `civicrm_tag` SET `label` = `name` WHERE `label` = ''; diff --git a/Civi/Api4/Service/Spec/Provider/TagCreationSpecProvider.php b/Civi/Api4/Service/Spec/Provider/TagCreationSpecProvider.php index dcfaeaff75..dce76d87fc 100644 --- a/Civi/Api4/Service/Spec/Provider/TagCreationSpecProvider.php +++ b/Civi/Api4/Service/Spec/Provider/TagCreationSpecProvider.php @@ -25,6 +25,8 @@ class TagCreationSpecProvider extends \Civi\Core\Service\AutoService implements */ public function modifySpec(RequestSpec $spec) { $spec->getFieldByName('used_for')->setDefaultValue('civicrm_contact'); + $spec->getFieldByName('name')->setRequired(FALSE)->setRequiredIf('empty($values.label)'); + $spec->getFieldByName('label')->setRequired(FALSE)->setRequiredIf('empty($values.name)'); } /** diff --git a/Civi/Test/Api3TestTrait.php b/Civi/Test/Api3TestTrait.php index d12f912bdb..d68b04de11 100644 --- a/Civi/Test/Api3TestTrait.php +++ b/Civi/Test/Api3TestTrait.php @@ -125,7 +125,7 @@ trait Api3TestTrait { * @param null $extraOutput * @return array|int */ - public function callAPIFailure($entity, $action, $params, $expectedErrorMessage = NULL, $extraOutput = NULL) { + public function callAPIFailure($entity, $action, $params = [], $expectedErrorMessage = NULL, $extraOutput = NULL) { if (is_array($params)) { $params += [ 'version' => $this->_apiversion, diff --git a/api/v3/Tag.php b/api/v3/Tag.php index 89bc9070ce..57434e4341 100644 --- a/api/v3/Tag.php +++ b/api/v3/Tag.php @@ -45,7 +45,6 @@ function civicrm_api3_tag_create($params) { */ function _civicrm_api3_tag_create_spec(&$params) { $params['used_for']['api.default'] = 'civicrm_contact'; - $params['name']['api.required'] = 1; $params['id']['api.aliases'] = ['tag']; } diff --git a/ext/search_kit/Civi/Search/Admin.php b/ext/search_kit/Civi/Search/Admin.php index 8232f25233..b32af91822 100644 --- a/ext/search_kit/Civi/Search/Admin.php +++ b/ext/search_kit/Civi/Search/Admin.php @@ -53,7 +53,7 @@ class Admin { ->setLoadOptions(['id', 'label']) ->execute()->first()['options'], 'tags' => Tag::get() - ->addSelect('id', 'name', 'color', 'is_selectable', 'description') + ->addSelect('id', 'label', 'color', 'is_selectable', 'description') ->addWhere('used_for', 'CONTAINS', 'civicrm_saved_search') ->execute(), ]; diff --git a/ext/search_kit/ang/crmSearchAdmin.module.js b/ext/search_kit/ang/crmSearchAdmin.module.js index 01947260a0..1b9adf9ffd 100644 --- a/ext/search_kit/ang/crmSearchAdmin.module.js +++ b/ext/search_kit/ang/crmSearchAdmin.module.js @@ -55,7 +55,7 @@ modules.push({text: label, id: key}); }, []), 'text'); this.getTags = function() { - return {results: formatForSelect2(CRM.crmSearchAdmin.tags, 'id', 'name', ['color', 'description'])}; + return {results: formatForSelect2(CRM.crmSearchAdmin.tags, 'id', 'label', ['color', 'description'])}; }; this.getPrimaryEntities = function() { diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminTags.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminTags.component.js index 0527d1a1c4..a17d18c02d 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminTags.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminTags.component.js @@ -64,9 +64,9 @@ } }; - this.makeTag = function(name) { + this.makeTag = function(label) { crmApi4('Tag', 'create', { - values: {name: name, color: ctrl.color, is_selectable: true, used_for: ['civicrm_saved_search']} + values: {label: label, color: ctrl.color, is_selectable: true, used_for: ['civicrm_saved_search']} }, 0).then(function(tag) { ctrl.allTags.push(tag); ctrl.toggleTag(tag); diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminTags.html b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminTags.html index 31711443dc..26e52e3bf0 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminTags.html +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdminTags.html @@ -16,14 +16,14 @@ {{ $ctrl.search }} -
  • +
  • - {{:: tag.name }} + {{:: tag.label }}
  • - {{:: $ctrl.getTag(id).name }} + {{:: $ctrl.getTag(id).label }} diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.ctrl.js b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.ctrl.js index bace427907..ed1ac2f9c2 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.ctrl.js +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.ctrl.js @@ -14,16 +14,16 @@ crmApi4({ tags: ['Tag', 'get', { - select: ['id', 'name', 'color', 'description', 'is_selectable', 'parent_id'], + select: ['id', 'label', 'color', 'description', 'is_selectable', 'parent_id'], where: [ ['is_tagset', '=', false], ['used_for:name', 'CONTAINS', this.entity], ['OR', [['parent_id', 'IS NULL'], ['parent_id.is_tagset', '=', false]]] ], - orderBy: {name: 'ASC'} + orderBy: {label: 'ASC'} }], tagsets: ['Tag', 'get', { - select: ['id', 'name'], + select: ['id', 'name', 'label'], where: [['is_tagset', '=', true], ['used_for:name', 'CONTAINS', this.entity]] }], }).then(function(result) { @@ -36,7 +36,7 @@ var sorted = _.transform(rawTags, function(sorted, tag) { sorted[tag.id] = { id: tag.id, - text: tag.name, + text: tag.label, description: tag.description, color: tag.color, disabled: !tag.is_selectable, diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.html b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.html index 51363c6e9d..d1bb6a09d8 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.html +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskTag.html @@ -28,7 +28,7 @@ >
    - + addValues([ [ - 'name' => ts('Non-profit'), + 'label' => ts('Non-profit'), + 'name' => 'Non_profit', 'description' => ts('Any not-for-profit organization.'), + 'color' => '#0bcb21', ], [ - 'name' => ts('Company'), + 'label' => ts('Company'), + 'name' => 'Company', 'description' => ts('For-profit organization.'), + 'color' => '#2260c3', ], [ - 'name' => ts('Government Entity'), + 'label' => ts('Government Entity'), + 'name' => 'Government_Entity', 'description' => ts('Any governmental entity.'), + 'color' => '#cd4b13', ], [ - 'name' => ts('Major Donor'), + 'label' => ts('Major Donor'), + 'name' => 'Major_Donor', 'description' => ts('High-value supporter of our organization.'), + 'color' => '#0cdae9', ], [ - 'name' => ts('Volunteer'), + 'label' => ts('Volunteer'), + 'name' => 'Volunteer', 'description' => ts('Active volunteers.'), + 'color' => '#f0dc00', ], ]); diff --git a/templates/CRM/Tag/Form/Edit.tpl b/templates/CRM/Tag/Form/Edit.tpl index 434ef8ecfb..e70aa192b8 100644 --- a/templates/CRM/Tag/Form/Edit.tpl +++ b/templates/CRM/Tag/Form/Edit.tpl @@ -12,8 +12,8 @@ {if $action eq 1 or $action eq 2} - - + + diff --git a/templates/CRM/Tag/Page/Tag.tpl b/templates/CRM/Tag/Page/Tag.tpl index 4caf65995f..5f37b01b81 100644 --- a/templates/CRM/Tag/Page/Tag.tpl +++ b/templates/CRM/Tag/Page/Tag.tpl @@ -24,7 +24,7 @@ {foreach from=$tagsets item=set}
  • - {$set.name} + {$set.label}
  • {/foreach} {if call_user_func(array('CRM_Core_Permission','check'), 'administer Tagsets')} @@ -164,7 +164,7 @@ function updateTagset(info) { tagSets[tagset].description = info.description; - tagSets[tagset].name = info.name; + tagSets[tagset].label = info.label; tagSets[tagset].used_for = info.used_for; tagSets[tagset].is_reserved = info.is_reserved; formatTagSet(tagSets[tagset]); @@ -175,7 +175,7 @@ function addTagsetHeader() { $('.tagset-header', $panel).remove(); $panel.prepend(tagsetHeaderTpl(tagSets[tagset])); - $("a[href='#tagset-" + tagset + "']").text(tagSets[tagset].name) + $("a[href='#tagset-" + tagset + "']").text(tagSets[tagset].label) .parent().toggleClass('is-reserved', tagSets[tagset].is_reserved == 1) .attr('title', ts('{/literal}{ts escape='js' 1='%1'}Tag Set for %1{/ts}{literal}', {'1': tagSets[tagset].used_for_label.join(', ')})); } @@ -188,7 +188,7 @@ e.preventDefault(); var sets = [{key: '0', value: '{/literal}{ts escape='js'}Main Tag Tree{/ts}{literal}'}]; _.each(tagSets, function(tagSet) { - sets.push({key: tagSet.id, value: tagSet.name}); + sets.push({key: tagSet.id, value: tagSet.label}); }); CRM.confirm({ title: '{/literal}{ts escape='js'}Move to Tagset{/ts}{literal}', @@ -321,7 +321,7 @@ tagSets[data.tag.id].display_name = user.display_name; formatTagSet(tagSets[data.tag.id]); $("#new-tagset").before('
    '); - $("a[href='#new-tagset']").parent().before('
  • ' + data.tag.name + '
  • '); + $("a[href='#new-tagset']").parent().before('
  • ' + data.tag.label + '
  • '); $('#mainTabContainer').tabs('refresh'); $('#mainTabContainer').tabs('option', 'active', -2); }); @@ -482,7 +482,7 @@

    title="{ts}Select color{/ts}" <% {rdelim} else {ldelim} %>disabled<% {rdelim} %> /> - <%- text %> + <%- text %>


    {ts}Description:{/ts} diff --git a/tests/phpunit/CRM/Core/BAO/TagTest.php b/tests/phpunit/CRM/Core/BAO/TagTest.php index fa395dba03..6168636597 100644 --- a/tests/phpunit/CRM/Core/BAO/TagTest.php +++ b/tests/phpunit/CRM/Core/BAO/TagTest.php @@ -18,13 +18,17 @@ class CRM_Core_BAO_TagTest extends CiviUnitTestCase { // Create an example hierarchy of tags. // The family tree of Abraham is used as a well known example of a hierarchy (no statement intended). // The order of ids is important because of: https://lab.civicrm.org/dev/core/-/issues/4049, that's why we create Isaac before Abraham. - CRM_Core_DAO::executeQuery("INSERT INTO civicrm_tag (id,name,used_for,is_tagset) VALUES(1, 'Isaac', 'civicrm_contact', 0);"); - CRM_Core_DAO::executeQuery("INSERT INTO civicrm_tag (id,name,used_for,is_tagset) VALUES(2, 'Abraham', 'civicrm_contact', 0);"); - CRM_Core_DAO::executeQuery("INSERT INTO civicrm_tag (id,name,used_for,is_tagset) VALUES(3, 'Jacob', 'civicrm_contact', 0);"); - CRM_Core_DAO::executeQuery("INSERT INTO civicrm_tag (id,name,used_for,is_tagset) VALUES(4, 'Ishmael', 'civicrm_contact', 1);"); - CRM_Core_DAO::executeQuery("INSERT INTO civicrm_tag (id,name,used_for,is_tagset) VALUES(5, 'Kedar', 'civicrm_contact', 1);"); - CRM_Core_DAO::executeQuery("INSERT INTO civicrm_tag (id,name,used_for,is_tagset) VALUES(6, 'Working', 'civicrm_activity', 1);"); - CRM_Core_DAO::executeQuery("INSERT INTO civicrm_tag (id,name,used_for,is_tagset) VALUES(7, 'Eating', 'civicrm_activity', 1);"); + CRM_Core_DAO::executeQuery(" + INSERT INTO civicrm_tag (id, name, label, used_for, is_tagset) + VALUES + (1, 'Isaac', 'Isaac', 'civicrm_contact', 0), + (2, 'Abraham', 'Abraham', 'civicrm_contact', 0), + (3, 'Jacob', 'Jacob', 'civicrm_contact', 0), + (4, 'Ishmael', 'Ishmael', 'civicrm_contact', 1), + (5, 'Kedar', 'Kedar', 'civicrm_contact', 1), + (6, 'Working', 'Working', 'civicrm_activity', 1), + (7, 'Eating', 'Eating', 'civicrm_activity', 1); + "); // Isaac is the son of abraham CRM_Core_DAO::executeQuery("UPDATE civicrm_tag SET parent_id = 2 WHERE name = 'Isaac';"); diff --git a/tests/phpunit/api/v3/TagTest.php b/tests/phpunit/api/v3/TagTest.php index d975f59889..fe741287a4 100644 --- a/tests/phpunit/api/v3/TagTest.php +++ b/tests/phpunit/api/v3/TagTest.php @@ -96,7 +96,7 @@ class api_v3_TagTest extends CiviUnitTestCase { */ public function testCreateEmptyParams($version) { $this->_apiversion = $version; - $result = $this->callAPIFailure('tag', 'create', [], 'name'); + $result = $this->callAPIFailure('tag', 'create'); } /** diff --git a/tests/phpunit/api/v4/Custom/PseudoconstantTest.php b/tests/phpunit/api/v4/Custom/PseudoconstantTest.php index 27fe1de015..ea8d8dc52e 100644 --- a/tests/phpunit/api/v4/Custom/PseudoconstantTest.php +++ b/tests/phpunit/api/v4/Custom/PseudoconstantTest.php @@ -272,6 +272,7 @@ class PseudoconstantTest extends CustomTestBase { $options = array_column($options, NULL, 'name'); $this->assertEquals('colorful', $options[$tag]['description']); $this->assertEquals('#aabbcc', $options[$tag]['color']); + $this->assertEquals($tag, $options[$tag]['name']); $this->assertEquals($tag, $options[$tag]['label']); } diff --git a/xml/schema/Core/EntityTag.xml b/xml/schema/Core/EntityTag.xml index ab063e8a7d..c39d45b2da 100644 --- a/xml/schema/Core/EntityTag.xml +++ b/xml/schema/Core/EntityTag.xml @@ -56,7 +56,8 @@
    {$form.name.label}{$form.name.html}{$form.label.label}{$form.label.html}
    {$form.description.label}
    civicrm_tag
    id - name + name + label is_tagset != 1 diff --git a/xml/schema/Core/Tag.xml b/xml/schema/Core/Tag.xml index 3d875d5346..620eb591e9 100644 --- a/xml/schema/Core/Tag.xml +++ b/xml/schema/Core/Tag.xml @@ -8,7 +8,7 @@ 1.1 true fa-tag - name + label id Tag ID @@ -30,9 +30,23 @@ varchar true 64 - Name of Tag. + Unique machine name 1.1 + + + label + Tag Label + User-facing tag name + true + varchar + 64 + + Text + + 5.68 + + description Description @@ -50,7 +64,8 @@ civicrm_tag
    id - name + name + label
    @@ -116,6 +131,7 @@ FK to civicrm_contact, who created this tag + EntityRef 3.4
    @@ -140,6 +156,13 @@ datetime Tag Created Date Date and time that tag was created. + CURRENT_TIMESTAMP + true + + Select Date + activityDateTime + + 3.4