-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
dev/core#155 Fix optiongroup is_reserved data and use when selecting option group for custom fields #12423
dev/core#155 Fix optiongroup is_reserved data and use when selecting option group for custom fields #12423
Conversation
(Standard links)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense, provided that we really do think the is_reserved
flag should be used for this purpose.
In addition to my code nitpicks, if option groups are getting saved as reserved
from the custom field screen, need to fix that as well.
UPDATE civicrm_option_group AS cog INNER JOIN civicrm_custom_field AS ccf | ||
ON cog.id = ccf.option_group_id | ||
SET cog.is_reserved = 0 WHERE cog.is_active = 1 AND ccf.is_active = 1; | ||
UPDATE civicrm_option_group SET is_reserved = 1 WHERE name='environment'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upgrade code does not affect new installs, so the environment
group needs to be set to reserved in the install sql as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colemanw I've updated the install sql as well now.
CRM/Custom/Form/Field.php
Outdated
$optionGroupParams = array( | ||
'is_reserved' => 0, | ||
'is_active' => 1, | ||
'options' => array('limit' => 0, 'sort' => "title ASC"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set a return
param here for efficiency if all you need is the title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
CRM/Custom/Form/Field.php
Outdated
$emptyOptGroup = FALSE; | ||
foreach ($optionGroupMetadata['values'] as $id => $metadata) { | ||
$optionGroups[$id] = $metadata['title']; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using CRM_Utils_Array::collect()
instead of a loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I didn't know about that function.
79cb9b0
to
91c29f6
Compare
… of only ones that are already linked to custom fields
91c29f6
to
56196ac
Compare
@colemanw Thankyou very much for your review. I've made the requested changes. Could you confirm if you are happy from a code perspective now? |
This is shaping up nicely. However we still need to change the custom field form postSave to create a non-reserved group when saving a custom field with a new set of options. Also I'm a little worried about non-reserved groups floating around in the system. Some extensions create option groups and they probably shouldn't be tampered with but extension authors may not have known to set them to reserved (I just checked and the api defaults to not reserved when creating a group). I guess we just post a memo to the dev channel about this and suggest extensions add an upgrade routine to reserve their option groups. |
56196ac
to
bd8a24d
Compare
@colemanw That is now changed. |
The whole thing re is_reserved was a bit of a mess before. Once we are happy for this to be merged I'll post a message to the dev list noting which version it will be in. |
I haven't had a chance to test this out yet but the code looks good and I agree with the concept. |
I tested the upgrade script and that I can now chose an unreserved option group. @colemanw has approved the concept so merging |
@eileenmcnaughton @mattwire This PR, specifically commit c0fce6b has broken the custom field edit form.
I think this is a critical regression and needs to be fixed immediately, but I'm hesitant to just revert this PR because it has an upgrade script. @mattwire - thoughts? |
Fix for issue editing custom fields with option groups after #12423
Overview
(Ref: #12235)
As the is_reserved flag is not being shown in the UI, and is not editable from the UI it has not been used for anything in core even though it is there.
A common use-case is adding an option group and then adding a set of custom fields that use that option group (eg. for surveys) but that is currently not possible via the UI because the query that looks for available option groups is looking ONLY for option groups that are already linked to custom fields - a catch 22!
Before
Not possible to create optiongroups via the UI that can be used with custom fields.
After
Option groups that are created via the UI can be selected for use with custom fields.
![customfieldoptiongroup](https://user-images.githubusercontent.com/2052161/40686294-c4040e3e-638e-11e8-803e-5b430757b589.png)
Technical Details
The is_reserved flag has always existed in the database but has not been used and has not been set correctly in some cases.
Comments
This fixes a common UI workflow where you need to create a set of options for use by a set of custom fields (for multiple choice questions/forms/surveys eg. forms used to calculate health scores etc.).
Currently you have to create the set of options along with the first custom field and you have no control over it's name. Currently, only when created in this way can you select that option group for use by other custom fields.