Skip to content

Commit

Permalink
Merge pull request #24164 from herbdool/core-3783
Browse files Browse the repository at this point in the history
dev/core#3783 convert Recent Items providers into an option group
  • Loading branch information
seamuslee001 authored Aug 9, 2022
2 parents 9a397a7 + 56919c1 commit f2c3457
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 19 deletions.
34 changes: 34 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveFiftyThree.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function upgrade_5_53_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Replace %A specifier in date settings.', 'replacePercentA');
$this->addTask('Add invoice pdf format', 'addInvoicePDFFormat');
$this->addTask('Add Recent Items Providers', 'addRecentItemsProviders');
}

/**
Expand Down Expand Up @@ -106,4 +107,37 @@ public static function getTemplatesUsingPercentA(): array {
return $usages;
}

/**
* dev/core#3783 Add Recent Items Providers.
* @return bool
*/
public static function addRecentItemsProviders() {
CRM_Core_BAO_OptionGroup::ensureOptionGroupExists([
'name' => 'recent_items_providers',
'title' => ts('Recent Items Providers'),
'is_reserved' => 0,
]);
$values = [
'Contact' => ['label' => ts('Contacts')],
'Relationship' => ['label' => ts('Relationships')],
'Activity' => ['label' => ts('Activities')],
'Note' => ['label' => ts('Notes')],
'Group' => ['label' => ts('Groups')],
'Case' => ['label' => ts('Cases')],
'Contribution' => ['label' => ts('Contributions')],
'Participant' => ['label' => ts('Participants')],
'Membership' => ['label' => ts('Memberships')],
'Pledge' => ['label' => ts('Pledges')],
'Event' => ['label' => ts('Events')],
'Campaign' => ['label' => ts('Campaigns')],
];
foreach ($values as $name => $value) {
CRM_Core_BAO_OptionValue::ensureOptionValueExists($value + [
'name' => $name,
'option_group_id' => 'recent_items_providers',
]);
}
return TRUE;
}

}
27 changes: 8 additions & 19 deletions CRM/Utils/Recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

use Civi\Api4\OptionValue;
use Civi\Api4\Utils\CoreUtil;

/**
Expand Down Expand Up @@ -340,28 +341,16 @@ private static function normalizeEntityType($entityType) {
/**
* 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');
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
use CRM_Grant_ExtensionUtil as E;

// Prevent errors during upgrades from < 5.53 that don't yet have the option group
$optionGroup = \Civi\Api4\OptionGroup::get(FALSE)
->addWhere('name', '=', 'recent_items_providers')
->selectRowCount()
->execute();
if (!$optionGroup->count()) {
return [];
}

return [
[
'name' => 'OptionGroup_recent_items_providers_OptionValue_Grant',
'entity' => 'OptionValue',
'cleanup' => 'always',
'update' => 'always',
'params' => [
'version' => 4,
'values' => [
'option_group_id.name' => 'recent_items_providers',
'label' => E::ts('Grants'),
'value' => 'Grant',
'name' => 'Grants',
'grouping' => NULL,
'filter' => 0,
'is_default' => FALSE,
'description' => NULL,
'is_optgroup' => FALSE,
'is_reserved' => FALSE,
'is_active' => TRUE,
'icon' => NULL,
'color' => NULL,
'component_id' => NULL,
'domain_id' => NULL,
'visibility_id' => NULL,
],
],
],
];
20 changes: 20 additions & 0 deletions xml/templates/civicrm_data.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1789,3 +1789,23 @@ INSERT IGNORE INTO civicrm_extension (type, full_name, name, label, file, is_act
INSERT IGNORE INTO civicrm_extension (type, full_name, name, label, file, is_active) VALUES ('module', 'ckeditor4', 'CKEditor4', 'CKEditor4', 'ckeditor4', 1);
INSERT IGNORE INTO civicrm_extension (type, full_name, name, label, file, is_active) VALUES ('module', 'legacycustomsearches', 'Custom search framework', 'Custom search framework', 'legacycustomsearches', 1);
INSERT IGNORE INTO civicrm_extension (type, full_name, name, label, file, is_active) VALUES ('module', 'org.civicrm.flexmailer', 'FlexMailer', 'FlexMailer', 'flexmailer', 1);

-- dev/core#3783 Recent Items providers
INSERT INTO civicrm_option_group (`name`, `title`, `is_reserved`, `is_active`) VALUES ('recent_items_providers', {localize}'{ts escape="sql"}Recent Items Providers{/ts}'{/localize}, 1, 1);

SELECT @option_group_id_recent := max(id) from civicrm_option_group where name = 'recent_items_providers';

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"}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);

0 comments on commit f2c3457

Please sign in to comment.