TypeError when trying to use checkboxes with default non-membership options in the Membership section of Contribution Pages
Overview
If you have a PriceSet with a checkboxes field, that has default options set that don't have a membership type associated with them, trying to use it on a Contribution Page causes that page to crash.
Observed on PHP 8.0, may not be an issue on 7.4 -
Reproduction steps
-
Create a membership price set
-
Include in this price set a Checkboxes fields with a default option that does not select a membership type, e.g. Membership Type
[ ] General - $100
[ ] Student - $50
Be awesome
[ X ] Donate $150 to save the Northern White Rhino
-
Use this price set in the membership context of a Contribution page
-
View the contribution page on the front-end
Current behaviour
Contribution page does not load, crashes with TypeError:
PHP Fatal error: Uncaught TypeError: strtolower(): Argument #1 ($string) must be of type string, array given in /.../public_html/ontarget/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php:1419
Backtrace shows this is called from CRM_Contribute_Form_Contribution_Main->setDefaultValues()
:
https://github.com/civicrm/civicrm-core/blob/4b75775/CRM/Contribute/Form/Contribution/Main.php#L270
(Ref 4b75775 is master at time of this report)
Expected behaviour
Contribution page should load, with defaults for all fields correctly applied
Environment information
- CiviCRM: Master, 5.70.2
- PHP: 8.0+
Comments
I have a working patch for this, however I'm not sure the approach is entirely correct. The code in question appears to be trying to insinuate a Membership Type ID for, again an option (PriceFieldValue) which doesn't specify a membership type. Perhaps this line could... just be removed?