From cec9440322a5d9c5aee5272cd246b9d6b4d8aadc Mon Sep 17 00:00:00 2001 From: Herb v/d Dool Date: Fri, 5 Aug 2022 14:56:31 -0400 Subject: [PATCH] dev/core#3783 convert Recent Items providers into an option group --- .../Incremental/sql/5.53.alpha1.mysql.tpl | 21 +++++++++++++++ CRM/Utils/Recent.php | 27 ++++++------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/CRM/Upgrade/Incremental/sql/5.53.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.53.alpha1.mysql.tpl index 51260ffa7e..4d4dfc1e83 100644 --- a/CRM/Upgrade/Incremental/sql/5.53.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.53.alpha1.mysql.tpl @@ -1 +1,22 @@ {* file to handle db changes in 5.53.alpha1 during upgrade *} + +-- dev/core#3783 Recent Items providers +INSERT INTO civicrm_option_group + (name, {localize field='title'}title{/localize}, is_reserved, is_active) VALUES ('recent_items_provider', {localize}'{ts escape="sql"}Recent Items Provider{/ts}'{/localize}, 0, 1); + +SELECT @option_group_id_recent := max(id) from civicrm_option_group where name = 'recent_items_provider'; +INSERT INTO civicrm_option_value (`option_group_id`, {localize field='label'}label{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, {localize field='description'}description{/localize}, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`) + VALUES + (@option_group_id_recent, {localize}'{ts escape="sql"}Contacts{/ts}'{/localize}, 'Contact', 'Contacts', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Relationships{/ts}'{/localize}, 'Relationship', 'Relationships', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Activities{/ts}'{/localize}, 'Activity', 'Activities', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Notes{/ts}'{/localize}, 'Note', 'Notes', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Groups{/ts}'{/localize}, 'Group', 'Groups', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Cases{/ts}'{/localize}, 'Case', 'Cases', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Contributions{/ts}'{/localize}, 'Contribution', 'Contributions', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Participants{/ts}'{/localize}, 'Participant', 'Participants', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Grants{/ts}'{/localize}, 'Grant', 'Grants', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Memberships{/ts}'{/localize}, 'Membership', 'Memberships', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Pledges{/ts}'{/localize}, 'Pledge', 'Pledges', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Events{/ts}'{/localize}, 'Event', 'Events', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL), + (@option_group_id_recent, {localize}'{ts escape="sql"}Campaigns{/ts}'{/localize}, 'Campaign', 'Campaigns', NULL, NULL, 0, 1, '', 0, 0, 1, NULL, NULL); diff --git a/CRM/Utils/Recent.php b/CRM/Utils/Recent.php index f09ce294bb..d364387132 100644 --- a/CRM/Utils/Recent.php +++ b/CRM/Utils/Recent.php @@ -14,6 +14,7 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Api4\OptionValue; use Civi\Api4\Utils\CoreUtil; /** @@ -340,28 +341,16 @@ class CRM_Utils_Recent { /** * Gets the list of available providers to civi's recent items stack * - * TODO: Make this an option group so extensions can extend it. - * * @return array */ public static function getProviders() { - $providers = [ - 'Contact' => ts('Contacts'), - 'Relationship' => ts('Relationships'), - 'Activity' => ts('Activities'), - 'Note' => ts('Notes'), - 'Group' => ts('Groups'), - 'Case' => ts('Cases'), - 'Contribution' => ts('Contributions'), - 'Participant' => ts('Participants'), - 'Grant' => ts('Grants'), - 'Membership' => ts('Memberships'), - 'Pledge' => ts('Pledges'), - 'Event' => ts('Events'), - 'Campaign' => ts('Campaigns'), - ]; - - return $providers; + return OptionValue::get(FALSE) + ->addWhere('option_group_id:name', '=', 'recent_items_providers') + ->addWhere('is_active', '=', TRUE) + ->addOrderBy('weight', 'ASC') + ->execute() + ->indexBy('value') + ->column('label'); } } -- 2.25.1