From cd43c5e3e0d23947f0227e3bc0766a16f2bec38c Mon Sep 17 00:00:00 2001
From: Allen Shaw <allen@emphanos.com>
Date: Wed, 1 May 2013 21:35:42 -0700
Subject: [PATCH] Refactored out of CRM_Core_PseudoConstant: tag(),
 customGroup(). CRM-12464

----------------------------------------
* CRM-12464:
  http://issues.civicrm.org/jira/browse/CRM-12464
---
 CRM/ACL/Form/ACL.php                          |  2 +-
 CRM/ACL/Page/ACL.php                          |  2 +-
 CRM/Activity/BAO/Query.php                    |  2 +-
 CRM/Case/BAO/Query.php                        |  2 +-
 CRM/Case/Form/ActivityView.php                |  2 +-
 CRM/Contact/BAO/Query.php                     |  2 +-
 CRM/Contact/Form/Search/Custom/Basic.php      |  2 +-
 CRM/Contact/Form/Search/Custom/Group.php      |  2 +-
 .../Form/Search/Custom/MultipleValues.php     |  2 +-
 CRM/Contact/Form/Search/Custom/Proximity.php  |  2 +-
 .../Form/Search/Custom/TagContributions.php   |  2 +-
 CRM/Contact/Import/Form/Preview.php           |  2 +-
 CRM/Core/BAO/File.php                         |  2 +-
 CRM/Core/BAO/UFGroup.php                      |  2 +-
 CRM/Core/Form/Tag.php                         |  6 +--
 CRM/Core/Permission.php                       |  2 +-
 CRM/Core/PseudoConstant.php                   | 51 -------------------
 CRM/Custom/Form/MoveField.php                 |  2 +-
 CRM/Event/BAO/Event.php                       |  2 +-
 CRM/Report/Form.php                           |  2 +-
 api/v3/EntityTag.php                          |  2 +-
 tests/phpunit/CRM/Core/PseudoConstantTest.php | 29 ++++++++++-
 tools/bin/scripts/ImportTags.php              |  2 +-
 .../org.civicrm.search.basic/Basic.php        |  2 +-
 xml/schema/Core/CustomField.xml               |  7 ++-
 xml/schema/Core/EntityTag.xml                 |  7 ++-
 26 files changed, 63 insertions(+), 79 deletions(-)

diff --git a/CRM/ACL/Form/ACL.php b/CRM/ACL/Form/ACL.php
index 23d04a76d5..77bd2664bf 100644
--- a/CRM/ACL/Form/ACL.php
+++ b/CRM/ACL/Form/ACL.php
@@ -166,7 +166,7 @@ class CRM_ACL_Form_ACL extends CRM_Admin_Form {
 
     $customGroup = array('-1' => ts('- select -'),
       '0' => ts('All Custom Groups'),
-    ) + CRM_Core_PseudoConstant::customGroup();
+    ) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
 
     $ufGroup = array('-1' => ts('- select -'),
       '0' => ts('All Profiles'),
diff --git a/CRM/ACL/Page/ACL.php b/CRM/ACL/Page/ACL.php
index 520faba798..7a0cd9cbc3 100644
--- a/CRM/ACL/Page/ACL.php
+++ b/CRM/ACL/Page/ACL.php
@@ -177,7 +177,7 @@ ORDER BY entity_id
     ) + CRM_Core_PseudoConstant::group();
     $customGroup = array('-1' => ts('- select -'),
       '0' => ts('All Custom Groups'),
-    ) + CRM_Core_PseudoConstant::customGroup();
+    ) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
     $ufGroup = array('-1' => ts('- select -'),
       '0' => ts('All Profiles'),
     ) + CRM_Core_PseudoConstant::ufGroup();
diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php
index 32bbd84635..4d7c551a28 100644
--- a/CRM/Activity/BAO/Query.php
+++ b/CRM/Activity/BAO/Query.php
@@ -342,7 +342,7 @@ class CRM_Activity_BAO_Query {
 
       case 'activity_tags':
         $value = array_keys($value);
-        $activityTags = CRM_Core_PseudoConstant::tag();
+        $activityTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
 
         $names = array();
         $val = array();
diff --git a/CRM/Case/BAO/Query.php b/CRM/Case/BAO/Query.php
index af40d21062..82b56c3774 100644
--- a/CRM/Case/BAO/Query.php
+++ b/CRM/Case/BAO/Query.php
@@ -492,7 +492,7 @@ class CRM_Case_BAO_Query {
           }
         }
       case 'case_tags':
-        $tags = CRM_Core_PseudoConstant::tag();
+        $tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
 
         if (is_array($value)) {
           foreach ($value as $k => $v) {
diff --git a/CRM/Case/Form/ActivityView.php b/CRM/Case/Form/ActivityView.php
index 3df941e3c9..5f8395ca50 100644
--- a/CRM/Case/Form/ActivityView.php
+++ b/CRM/Case/Form/ActivityView.php
@@ -84,7 +84,7 @@ class CRM_Case_Form_ActivityView extends CRM_Core_Form {
 
     $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity');
     if (!empty($tags)) {
-      $allTag = CRM_Core_PseudoConstant::tag();
+      $allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
       foreach ($tags as $tid) {
         $tags[$tid] = $allTag[$tid];
       }
diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php
index fba6b89eba..16f392f481 100644
--- a/CRM/Contact/BAO/Query.php
+++ b/CRM/Contact/BAO/Query.php
@@ -2710,7 +2710,7 @@ WHERE  id IN ( $groupIDs )
   function tag(&$values) {
     list($name, $op, $value, $grouping, $wildcard) = $values;
 
-    $tagNames = CRM_Core_PseudoConstant::tag();
+    $tagNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     if (is_array($value)) {
       if (count($value) > 1) {
         $this->_useDistinct = TRUE;
diff --git a/CRM/Contact/Form/Search/Custom/Basic.php b/CRM/Contact/Form/Search/Custom/Basic.php
index ddcf2fb2d6..f55c4ef055 100644
--- a/CRM/Contact/Form/Search/Custom/Basic.php
+++ b/CRM/Contact/Form/Search/Custom/Basic.php
@@ -113,7 +113,7 @@ class CRM_Contact_Form_Search_Custom_Basic extends CRM_Contact_Form_Search_Custo
     $form->addElement('select', 'group', ts('in'), $group);
 
     // add select for categories
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tagged'), $tag);
 
     // text for sort_name
diff --git a/CRM/Contact/Form/Search/Custom/Group.php b/CRM/Contact/Form/Search/Custom/Group.php
index bfc95e9eba..a9d16c2193 100644
--- a/CRM/Contact/Form/Search/Custom/Group.php
+++ b/CRM/Contact/Form/Search/Custom/Group.php
@@ -91,7 +91,7 @@ class CRM_Contact_Form_Search_Custom_Group extends CRM_Contact_Form_Search_Custo
 
     $groups = CRM_Core_PseudoConstant::group();
 
-    $tags = CRM_Core_PseudoConstant::tag();
+    $tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     if (count($groups) == 0 || count($tags) == 0) {
       CRM_Core_Session::setStatus(ts("At least one Group and Tag must be present for Custom Group / Tag search."), ts('Missing Group/Tag'));
       $url = CRM_Utils_System::url('civicrm/contact/search/custom/list', 'reset=1');
diff --git a/CRM/Contact/Form/Search/Custom/MultipleValues.php b/CRM/Contact/Form/Search/Custom/MultipleValues.php
index fb873f3e05..d7bc2c62a2 100644
--- a/CRM/Contact/Form/Search/Custom/MultipleValues.php
+++ b/CRM/Contact/Form/Search/Custom/MultipleValues.php
@@ -104,7 +104,7 @@ class CRM_Contact_Form_Search_Custom_MultipleValues extends CRM_Contact_Form_Sea
     $form->addElement('select', 'group', ts('in'), $group);
 
     // add select for tags
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tagged'), $tag);
 
     if (empty($this->_groupTree)) {
diff --git a/CRM/Contact/Form/Search/Custom/Proximity.php b/CRM/Contact/Form/Search/Custom/Proximity.php
index 9d17cc8415..d374ddf4ee 100644
--- a/CRM/Contact/Form/Search/Custom/Proximity.php
+++ b/CRM/Contact/Form/Search/Custom/Proximity.php
@@ -134,7 +134,7 @@ class CRM_Contact_Form_Search_Custom_Proximity extends CRM_Contact_Form_Search_C
     $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
     $form->addElement('select', 'group', ts('Group'), $group);
 
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tag'), $tag);
 
 
diff --git a/CRM/Contact/Form/Search/Custom/TagContributions.php b/CRM/Contact/Form/Search/Custom/TagContributions.php
index 35aa7691fa..5b24abfc9a 100644
--- a/CRM/Contact/Form/Search/Custom/TagContributions.php
+++ b/CRM/Contact/Form/Search/Custom/TagContributions.php
@@ -64,7 +64,7 @@ class CRM_Contact_Form_Search_Custom_TagContributions implements CRM_Contact_For
 
     $form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom'));
     $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tagged'), $tag);
 
     /**
diff --git a/CRM/Contact/Import/Form/Preview.php b/CRM/Contact/Import/Form/Preview.php
index f81f354eff..f84341e2ba 100644
--- a/CRM/Contact/Import/Form/Preview.php
+++ b/CRM/Contact/Import/Form/Preview.php
@@ -72,7 +72,7 @@ class CRM_Contact_Import_Form_Preview extends CRM_Core_Form {
     $groups = CRM_Core_PseudoConstant::group();
     $this->set('groups', $groups);
 
-    $tag = CRM_Core_PseudoConstant::tag();
+    $tag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     if ($tag) {
       $this->set('tag', $tag);
     }
diff --git a/CRM/Core/BAO/File.php b/CRM/Core/BAO/File.php
index 18f29a8b90..9826726a67 100644
--- a/CRM/Core/BAO/File.php
+++ b/CRM/Core/BAO/File.php
@@ -284,7 +284,7 @@
      }
 
      //fix tag names
-     $tags = CRM_Core_PseudoConstant::tag();
+     $tags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
 
      foreach($results as &$values) {
        if (!empty($values['tag'])) {
diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php
index 6fdaa2a516..777444d25f 100644
--- a/CRM/Core/BAO/UFGroup.php
+++ b/CRM/Core/BAO/UFGroup.php
@@ -1008,7 +1008,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
         }
         elseif ($name == 'tag') {
           $entityTags = CRM_Core_BAO_EntityTag::getTag($cid);
-          $allTags    = CRM_Core_PseudoConstant::tag();
+          $allTags    = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
           $title      = array();
           foreach ($entityTags as $tagId) {
             $title[] = $allTags[$tagId];
diff --git a/CRM/Core/Form/Tag.php b/CRM/Core/Form/Tag.php
index 323599f12b..f329eb627d 100644
--- a/CRM/Core/Form/Tag.php
+++ b/CRM/Core/Form/Tag.php
@@ -123,7 +123,7 @@ class CRM_Core_Form_Tag {
               if (!empty($form->_submitValues['activity_taglist']) &&
                 CRM_Utils_Array::value($parentId, $form->_submitValues['activity_taglist'])
               ) {
-                $allTags = CRM_Core_PseudoConstant::tag();
+                $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $tagIds = explode(',', $form->_submitValues['activity_taglist'][$parentId]);
                 foreach ($tagIds as $tagId) {
                   if (is_numeric($tagId)) {
@@ -144,7 +144,7 @@ class CRM_Core_Form_Tag {
               if (!empty($form->_submitValues['case_taglist']) &&
                 CRM_Utils_Array::value($parentId, $form->_submitValues['case_taglist'])
               ) {
-                $allTags = CRM_Core_PseudoConstant::tag();
+                $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                 $tagIds = explode(',', $form->_submitValues['case_taglist'][$parentId]);
                 foreach ($tagIds as $tagId) {
                   if (is_numeric($tagId)) {
@@ -169,7 +169,7 @@ class CRM_Core_Form_Tag {
                 if (!empty($form->_submitValues["attachment_taglist_$i"]) &&
                   CRM_Utils_Array::value($parentId, $form->_submitValues["attachment_taglist_$i"])
                 ) {
-                  $allTags = CRM_Core_PseudoConstant::tag();
+                  $allTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
                   $tagIds = explode(',', $form->_submitValues["attachment_taglist_$i"][$parentId]);
                   foreach ($tagIds as $tagId) {
                     if (is_numeric($tagId)) {
diff --git a/CRM/Core/Permission.php b/CRM/Core/Permission.php
index 2e7facdfe7..d3c318cdbc 100644
--- a/CRM/Core/Permission.php
+++ b/CRM/Core/Permission.php
@@ -173,7 +173,7 @@ class CRM_Core_Permission {
   }
 
   public static function customGroup($type = CRM_Core_Permission::VIEW, $reset = FALSE) {
-    $customGroups = CRM_Core_PseudoConstant::customGroup($reset);
+    $customGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id', array('fresh' => $reset));
     $defaultGroups = array();
 
     // check if user has all powerful permission
diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php
index a835fb3336..dea911b368 100644
--- a/CRM/Core/PseudoConstant.php
+++ b/CRM/Core/PseudoConstant.php
@@ -105,13 +105,6 @@ class CRM_Core_PseudoConstant {
    */
   private static $countryIsoCode;
 
-  /**
-   * tag
-   * @var array
-   * @static
-   */
-  private static $tag;
-
   /**
    * group
    * @var array
@@ -147,13 +140,6 @@ class CRM_Core_PseudoConstant {
    */
   private static $ufGroup;
 
-  /**
-   * custom groups
-   * @var array
-   * @static
-   */
-  private static $customGroup;
-
   /**
    * currency codes
    * @var array
@@ -757,28 +743,6 @@ WHERE  id = %1";
     return self::$countryIsoCode;
   }
 
-  /**
-   * Get all the categories from database.
-   *
-   * The static array tag is returned, and if it's
-   * called the first time, the <b>Tag DAO</b> is used
-   * to get all the categories.
-   *
-   * Note: any database errors will be trapped by the DAO.
-   *
-   * @access public
-   * @static
-   *
-   * @return array - array reference of all categories.
-   *
-   */
-  public static function &tag() {
-    if (!self::$tag) {
-      self::populate(self::$tag, 'CRM_Core_DAO_Tag', TRUE);
-    }
-    return self::$tag;
-  }
-
   /**
    * Get all groups from database
    *
@@ -896,21 +860,6 @@ WHERE  id = %1";
     return self::$staticGroup;
   }
 
-  /**
-   * Get all the custom groups
-   *
-   * @access public
-   *
-   * @return array - array reference of all groups.
-   * @static
-   */
-  public static function &customGroup($reset = FALSE) {
-    if (!self::$customGroup || $reset) {
-      self::populate(self::$customGroup, 'CRM_Core_DAO_CustomGroup', FALSE, 'title', 'is_active', NULL, 'title');
-    }
-    return self::$customGroup;
-  }
-
   /**
    * Get all the user framework groups
    *
diff --git a/CRM/Custom/Form/MoveField.php b/CRM/Custom/Form/MoveField.php
index 1e4f04dd4f..f44a86d7ad 100644
--- a/CRM/Custom/Form/MoveField.php
+++ b/CRM/Custom/Form/MoveField.php
@@ -110,7 +110,7 @@ class CRM_Custom_Form_MoveField extends CRM_Core_Form {
    */
   public function buildQuickForm() {
 
-    $customGroup = CRM_Core_PseudoConstant::customGroup();
+    $customGroup = CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
     unset($customGroup[$this->_srcGID]);
     if (empty($customGroup)) {
       CRM_Core_Error::statusBounce(ts('You need more than one custom group to move fields'));
diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php
index 46d0bdc282..c3df182990 100644
--- a/CRM/Event/BAO/Event.php
+++ b/CRM/Event/BAO/Event.php
@@ -1425,7 +1425,7 @@ WHERE civicrm_event.is_active = 1
         }
         elseif ($name == 'tag') {
           $entityTags = $params[$name];
-          $allTags    = CRM_Core_PseudoConstant::tag();
+          $allTags    = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
           $title      = array();
           if (is_array($entityTags)) {
             foreach ($entityTags as $tagId => $dontCare) {
diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php
index 57e3f95989..49b956bca5 100644
--- a/CRM/Report/Form.php
+++ b/CRM/Report/Form.php
@@ -259,7 +259,7 @@ class CRM_Report_Form extends CRM_Core_Form {
     }
 
     // Get all custom groups
-    $allGroups = CRM_Core_PseudoConstant::customGroup();
+    $allGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
 
     // Get the custom groupIds for which the user have VIEW permission
     require_once 'CRM/ACL/API.php';
diff --git a/api/v3/EntityTag.php b/api/v3/EntityTag.php
index ed36e5a6b7..3367acf811 100644
--- a/api/v3/EntityTag.php
+++ b/api/v3/EntityTag.php
@@ -97,7 +97,7 @@ function civicrm_api3_entity_tag_display($params) {
 
   $values = CRM_Core_BAO_EntityTag::getTag($entityID, $entityTable);
   $result = array();
-  $tags   = CRM_Core_PseudoConstant::tag();
+  $tags   = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
   foreach ($values as $v) {
     $result[] = $tags[$v];
   }
diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php
index 107164f1d7..0b8610b3b3 100644
--- a/tests/phpunit/CRM/Core/PseudoConstantTest.php
+++ b/tests/phpunit/CRM/Core/PseudoConstantTest.php
@@ -43,16 +43,41 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase {
     parent::setUp();
   }
 
+  /**
+   * Assure CRM_Core_PseudoConstant::get() is working properly for a range of
+   * DAO fields having a <pseudoconstant> tag in the XML schema.
+   */
   function testOptionValues() {
-    /*
+    $custom_group_name = 'Test custom group';
+    $api_params = array(
+        'version' => 3,
+        'title' => $custom_group_name,
+        'extends' => 'Individual',
+    );
+    civicrm_api('customGroup', 'create', $api_params);
+
+    /**
      * daoName/field combinations to test
-     * array[DAO Name] = properties, where properties can be:
+     * Format: array[DAO Name] = $properties, where properties is an array whose
+     * named members can be:
      * - fieldName: the SQL column name within the DAO table.
      * - sample: Any one value which is expected in the list of option values.
      * - exclude: Any one value which should not be in the list.
      * - max: integer (default = 10) maximum number of option values expected.
      */
     $fields = array(
+      'CRM_Core_DAO_CustomField' => array(
+        array(
+          'fieldName' => 'custom_group_id',
+          'sample' => $custom_group_name,
+        ),
+      ),
+      'CRM_Core_DAO_EntityTag' => array(
+        array(
+          'fieldName' => 'tag_id',
+          'sample' => 'Government Entity',
+        ),
+      ),
       'CRM_Core_DAO_OptionValue' => array(
         array(
           'fieldName' => 'component_id',
diff --git a/tools/bin/scripts/ImportTags.php b/tools/bin/scripts/ImportTags.php
index c719561c9e..eddc8a6986 100644
--- a/tools/bin/scripts/ImportTags.php
+++ b/tools/bin/scripts/ImportTags.php
@@ -34,7 +34,7 @@ class tagsImporter extends civicrm_cli {
       die("you need to profide a csv file (1st column parent name, 2nd tag name");
     }
     $this->file = $this->args[0];
-    $this->tags = array_flip(CRM_Core_PseudoConstant::tag());
+    $this->tags = array_flip(CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)));
   }
 
   //format expected: parent name, tag
diff --git a/tools/extensions/org.civicrm.search.basic/Basic.php b/tools/extensions/org.civicrm.search.basic/Basic.php
index 4a489a851d..f1be81b191 100644
--- a/tools/extensions/org.civicrm.search.basic/Basic.php
+++ b/tools/extensions/org.civicrm.search.basic/Basic.php
@@ -102,7 +102,7 @@ class org_civicrm_search_basic extends CRM_Contact_Form_Search_Custom_Baseimplem
     $form->addElement('select', 'group', ts('in'), $group);
 
     // add select for categories
-    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
+    $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tagged'), $tag);
 
     // text for sort_name
diff --git a/xml/schema/Core/CustomField.xml b/xml/schema/Core/CustomField.xml
index 81b4722695..d38c353a5e 100644
--- a/xml/schema/Core/CustomField.xml
+++ b/xml/schema/Core/CustomField.xml
@@ -23,7 +23,12 @@
       <type>int unsigned</type>
       <required>true</required>
       <comment>FK to civicrm_custom_group.</comment>
-       <add>1.1</add>
+      <add>1.1</add>
+      <pseudoconstant>
+        <table>civicrm_custom_group</table>
+        <keyColumn>id</keyColumn>
+        <labelColumn>title</labelColumn>
+      </pseudoconstant>
   </field>
   <foreignKey>
        <name>custom_group_id</name>
diff --git a/xml/schema/Core/EntityTag.xml b/xml/schema/Core/EntityTag.xml
index 6875b2136e..89ff9eb2ca 100644
--- a/xml/schema/Core/EntityTag.xml
+++ b/xml/schema/Core/EntityTag.xml
@@ -68,7 +68,12 @@
       <title>Tag ID</title>
       <required>true</required>
       <comment>FK to civicrm_tag</comment>
-       <add>1.1</add>
+      <add>1.1</add>
+      <pseudoconstant>
+        <table>civicrm_tag</table>
+        <keyColumn>id</keyColumn>
+        <labelColumn>name</labelColumn>
+      </pseudoconstant>
   </field>
   <foreignKey>
        <name>tag_id</name>
-- 
GitLab