-
-
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#244 Allow use of custom fields of type select without specifying an optiongroup #12440
dev/core#244 Allow use of custom fields of type select without specifying an optiongroup #12440
Conversation
(Standard links)
|
@@ -419,9 +419,6 @@ public function getOptions($context = NULL) { | |||
elseif ($this->data_type === 'Boolean') { | |||
$options = $context == 'validate' ? array(0, 1) : CRM_Core_SelectValues::boolean(); | |||
} | |||
else { | |||
return FALSE; | |||
} | |||
CRM_Utils_Hook::customFieldOptions($this->id, $options, FALSE); | |||
CRM_Utils_Hook::fieldOptions($this->getEntity(), "custom_{$this->id}", $options, array('context' => $context)); | |||
return $options; |
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.
don't you need to define $options = FALSE at the start to avoid e-notices?
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.
@eileenmcnaughton Yes I do, and now I have :-)
…n option group (so they can be populated dynamically using hook_civicrm_fieldOptions
ec15a25
to
6c5d3fc
Compare
Hmm, I think there's more than just 1 place where this assumption is made. I'm going to work up an api4 patch to better guess whether a field may have associated options, bearing this in mind. |
I think this is right |
Overview
For an extension I had a requirement to add a "Select Month" custom field. The options are populated dynamically using hook_civicrm_fieldOptions and there is no need for an option group to be associated with them (manually specifying the months of the year in an optiongroup means they won't be updated to match the current locale).
Additionally, if populated dynamically using the hook_civicrm_fieldOptions and there is an optiongroup associated with the field, the "Edit options" element is automatically added to the UI which is not desirable and does not work properly as the optiongroup is not populated.
There is a single line in CRM_Core_BAO_CustomField::getOptions which causes the function to return before calling hooks if the element is a Select and doesn't have an option group defined which makes it impossible to populate the field using hooks. Removing this allows the hook to populate the custom field values and everything works.
For an example see https://github.com/mattwire/uk.co.mjwconsult.variablerecurpayments (Edit a Membership Type and select the Pro-Rata Start Month).
#12439 is also required.
Before
Could not dynamically populate a custom field of type select using hooks without specifying an optiongroup as well.
After
Can dynamically populate a custom field of type select using hooks without specifying an optiongroup (create the custom field via XML or API).
Technical Details
The code makes an assumption in one place that a select element will have an optiongroup. But this unnecessarily restricts the ability to dynamically populate the fields.
https://lab.civicrm.org/dev/core/issues/244