Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Switch OptionGroup BAO to use new centralized logic to make name from title #22654

Merged
merged 1 commit into from
Feb 3, 2022

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Jan 28, 2022

Overview

Refactors OptionGroup code to use centralized logic from #22570

Before

Some artistically creative code in OptionGroup BAO to make a name from the title.

After

OptionGroup BAO add function deprecated, which triggers APIv4 to use writeRecords() with its centralized logic for creating name from title.
APIv3 kept the same to minimize impact on existing code.

Notes

I stumbled into this because I was writing a unit test which created two custom field groups with the same named fields in both groups. The current "artistic" approach to creating a unique name was to append a timestamp to it, but in a unit test the fields are created at the same time, so this didn't work.
I decided to do this refactor to move things in a more standardized direction; it required extending the CRM_Core_DAO::makeNameFromLabel function to handle titles as well as labels, and to cope better with the maxlength of the name field.

@civibot
Copy link

civibot bot commented Jan 28, 2022

(Standard links)

… title

Switches APIv4 to use writeRecords for the OptionGroup entity;
keeps v3 the same for backward-compatability.
@@ -423,6 +423,7 @@ public static function toBeSkipped_custom_data_creatable($sequential = FALSE) {
'Profile',
'Payment',
'Order',
'OptionGroup',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR triggered a bizarre test failure, why it ever worked before I don't know, but no, attaching custom data to the OptionGroup entity makes no sense.

$optionGroup->save();
$customGroupTitle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'title');
$optionGroup = CRM_Core_DAO_OptionGroup::writeRecord([
'title' => "$customGroupTitle :: {$params['label']}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is a material change it seems @colemanw what prompted this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in order to take advantage of the auto-name-generation, I needed to switch from direct DAO insert to using the WriteRecord function. The name gets derived from the title, which previously was just the label of the custom field. I wanted it to be more descriptive. It doesn't matter too much because neither name nor title are ever shown in the UI anywhere for auto-generated custom groups, but for techie looking at the sql table and trying to make sense of what's in it, I thought this more precise label would be nice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colemanw are they shown at the list of option groups i.e. at /admin/options?reset=1 also as part of a drop down when creating a new custom field right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you kind of have to go looking for it, but it will show in the UI in those places. Again, because you have to go looking, I think the name of the custom group + the name of the custom field is an improvement over just the field name.

@seamuslee001 seamuslee001 merged commit 09accb9 into civicrm:master Feb 3, 2022
@seamuslee001 seamuslee001 deleted the optionGroupName branch February 3, 2022 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants