Convert Notes to use option_group instead of hardcoded list
authorColeman Watts <coleman@civicrm.org>
Tue, 8 Jun 2021 12:37:38 +0000 (08:37 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 17 Jun 2021 18:26:11 +0000 (14:26 -0400)
CRM/Core/BAO/Note.php
CRM/Core/DAO/Note.php
CRM/Upgrade/Incremental/php/FiveForty.php
xml/schema/Core/Note.xml
xml/templates/civicrm_data.tpl

index a08dbacf4faad35694c58b854e2497b488616bae..85cc99bd2b3a6666a42b870b8365db0fed649308 100644 (file)
@@ -565,17 +565,4 @@ WHERE participant.contact_id = %1 AND  note.entity_table = 'civicrm_participant'
     }
   }
 
-  /**
-   * Whitelist of possible values for the entity_table field
-   * @return array
-   */
-  public static function entityTables() {
-    return array(
-      'civicrm_relationship' => 'Relationship',
-      'civicrm_contact' => 'Contact',
-      'civicrm_participant' => 'Participant',
-      'civicrm_contribution' => 'Contribution',
-    );
-  }
-
 }
index 35067ea2924c30d36825b0113fa571517b62032d..4370b6d075e4ed416888b9ab22dadbb5e4281985 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Core/Note.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:a84f607a5a29a8977287f694f05ab721)
+ * (GenCodeChecksum:49a15912788803e8ccf5298fe93932aa)
  */
 
 /**
@@ -180,7 +180,8 @@ class CRM_Core_DAO_Note extends CRM_Core_DAO {
           'bao' => 'CRM_Core_BAO_Note',
           'localizable' => 0,
           'pseudoconstant' => [
-            'callback' => 'CRM_Core_BAO_Note::entityTables',
+            'optionGroupName' => 'note_used_for',
+            'optionEditPath' => 'civicrm/admin/options/note_used_for',
           ],
           'add' => '1.1',
         ],
index a27a7809703de318d9797c20f4da84178317870a..83ddaf411eeaef924e318f177356a8b0abb51a74 100644 (file)
@@ -51,9 +51,34 @@ class CRM_Upgrade_Incremental_php_FiveForty extends CRM_Upgrade_Incremental_Base
 
   public function upgrade_5_40_alpha1($rev) {
     $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
+    $this->addTask('Add option list for group_used_for', 'addGroupOptionList');
     $this->addTask('core-issue#2486  - Add product_id foreign key to civicrm_contribution_product', 'addContributionProductFK');
   }
 
+  /**
+   * @param CRM_Queue_TaskContext $ctx
+   * @return bool
+   */
+  public static function addGroupOptionList(CRM_Queue_TaskContext $ctx) {
+    $optionGroupId = \CRM_Core_BAO_OptionGroup::ensureOptionGroupExists([
+      'name' => 'note_used_for',
+      'title' => ts('Note Used For'),
+      'is_reserved' => 1,
+      'is_active' => 1,
+      'is_locked' => 1,
+    ]);
+    $values = [
+      ['value' => 'civicrm_relationship', 'name' => 'Relationship', 'label' => ts('Relationships')],
+      ['value' => 'civicrm_contact', 'name' => 'Contact', 'label' => ts('Contacts')],
+      ['value' => 'civicrm_participant', 'name' => 'Participant', 'label' => ts('Participants')],
+      ['value' => 'civicrm_contribution', 'name' => 'Contribution', 'label' => ts('Contributions')],
+    ];
+    foreach ($values as $value) {
+      \CRM_Core_BAO_OptionValue::ensureOptionValueExists($value + ['option_group_id' => $optionGroupId]);
+    }
+    return TRUE;
+  }
+
   /**
    * @param \CRM_Queue_TaskContext $ctx
    *
index dd0ef304a5b0eb48bda02cb2f9b4eaae49897525..87f9b45f6541497d60c4956e753d4242216f81d6 100644 (file)
@@ -31,7 +31,7 @@
     <required>true</required>
     <comment>Name of table where item being referenced is stored.</comment>
     <pseudoconstant>
-      <callback>CRM_Core_BAO_Note::entityTables</callback>
+      <optionGroupName>note_used_for</optionGroupName>
     </pseudoconstant>
     <add>1.1</add>
   </field>
index 78986708852d65f2019032ba9ab4cb42a52eb47b..24f7ab5171b029fe41dfddbb103666b15cfdc7ba 100644 (file)
@@ -164,6 +164,7 @@ VALUES
    ('contact_reference_options'     , '{ts escape="sql"}Contact Reference Autocomplete Options{/ts}', NULL, 1, 1, 1),
    ('website_type'                  , '{ts escape="sql"}Website Type{/ts}'                       , NULL, 1, 1, 0),
    ('tag_used_for'                  , '{ts escape="sql"}Tag Used For{/ts}'                       , NULL, 1, 1, 1),
+   ('note_used_for'                 , '{ts escape="sql"}Note Used For{/ts}'                      , NULL, 1, 1, 1),
    ('currencies_enabled'            , '{ts escape="sql"}Currencies Enabled{/ts}'                 , NULL, 1, 1, 0),
    ('event_badge'                   , '{ts escape="sql"}Event Name Badge{/ts}'                   , NULL, 1, 1, 0),
    ('note_privacy'                  , '{ts escape="sql"}Privacy levels for notes{/ts}'           , NULL, 1, 1, 0),
@@ -248,6 +249,7 @@ SELECT @option_group_id_acsOpt         := max(id) from civicrm_option_group wher
 SELECT @option_group_id_acConRef       := max(id) from civicrm_option_group where name = 'contact_reference_options';
 SELECT @option_group_id_website        := max(id) from civicrm_option_group where name = 'website_type';
 SELECT @option_group_id_tuf            := max(id) from civicrm_option_group where name = 'tag_used_for';
+SELECT @option_group_id_nuf            := max(id) from civicrm_option_group where name = 'note_used_for';
 SELECT @option_group_id_currency       := max(id) from civicrm_option_group where name = 'currencies_enabled';
 SELECT @option_group_id_eventBadge     := max(id) from civicrm_option_group where name = 'event_badge';
 SELECT @option_group_id_notePrivacy    := max(id) from civicrm_option_group where name = 'note_privacy';
@@ -755,6 +757,12 @@ VALUES
    (@option_group_id_tuf, '{ts escape="sql"}Cases{/ts}',       'civicrm_case',     'Case',     NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL, NULL),
    (@option_group_id_tuf, '{ts escape="sql"}Attachments{/ts}', 'civicrm_file',     'File',     NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL, NULL),
 
+-- Note used for
+   (@option_group_id_nuf, '{ts escape="sql"}Contacts{/ts}',      'civicrm_contact',      'Contact',      NULL, 0, NULL, 1, NULL, 0, 0, 1, NULL, NULL, NULL),
+   (@option_group_id_nuf, '{ts escape="sql"}Relationships{/ts}', 'civicrm_relationship', 'Relationship', NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL, NULL),
+   (@option_group_id_nuf, '{ts escape="sql"}Participants{/ts}',  'civicrm_participant',  'Participant',  NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL, NULL),
+   (@option_group_id_nuf, '{ts escape="sql"}Contributions{/ts}', 'civicrm_contribution', 'Contribution', NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL, NULL),
+
    (@option_group_id_currency, 'USD ($)',      'USD',     'USD',       NULL, 0, 1, 1, NULL, 0, 0, 1, NULL, NULL, NULL),
 
 -- event name badges