Deprecated function error in Custom Searches.
Overview
This message appears when opening some custom searches, e.g. Household Name and State.
User deprecated function: Attributes passed to CRM_Core_Form::add() are not an array. Caller: CRM_Contact_Form_Search_Custom_Sample::buildForm in CRM_Core_Error::deprecatedWarning() (line 1059 of /srv/buildkit/build/dmaster/web/sites/all/modules/civicrm/CRM/Core/Error.php).
Similar errors occur in Zip Code Range and Custom Group Multiple Values Listing
This is not the same as #3051 (closed)
Reproduction steps
Current behaviour
What happens currently. Please provide error messages, screenshots or gifs (LICEcap, SilentCast) where appropriate.
User deprecated function: Attributes passed to CRM_Core_Form::add() are not an array. Caller: CRM_Contact_Form_Search_Custom_Sample::buildForm in CRM_Core_Error::deprecatedWarning() (line 1059 of /srv/buildkit/build/dmaster/web/sites/all/modules/civicrm/CRM/Core/Error.php).
Expected behaviour
What should happen. The message shouldn't appear. Environment information
- Browser: Microsoft Edge but probably not relevant.
- CiviCRM: 5.48.alpha1/5.46.0/... The former is the demo site.
- PHP: 7.3.33-1+0~20211119.91+debian10~1.gbp618351/8.0/7.4..._ but probably not relevant.
- CMS: Drupal /Drupal 9.3.5/... but probably not relevant.
- Database: Whatever runs the demo site/MySQL 8.0.28/... but probably not relevant.
- Web Server: Whatever runs the demo site/IIS 10/... but probably not relevant.
Comments
Anything else you would like the reviewer to note. I did some investigation. The problem in Household Name and State is caused by these lines in
<drupal root>/vendor/civicrm/civicrm-core/ext/legacycustomsearches/CRM/Contact/Form/Search/Custom/Sample.php
Lines 51 - 54 in 5.46.0
$form->add('text',
'household_name',
ts('Household Name'),
TRUE
);
The fourth parameter (TRUE) is not an array, but unless the type is 'static', expects the attribute (fourth parameter) to be an array.
<drupal root>/vendor/civicrm/civicrm-core/CRM/Core/Form.php
These lines solve the problem.
$attrib[] = TRUE;
$form->add('text',
'household_name',
ts('Household Name'),
$attrib
);
In Zip Code Range the offending lines are 48 - 58 in:
<drupal root>/vendor/civicrm\/civicrm-core/ext/legacycustomsearches/CRM/Contact/Form/Search/Custom/ZipCodeRange.php
$form->add('text',
'postal_code_low',
ts('Postal Code Start'),
TRUE
);
$form->add('text',
'postal_code_high',
ts('Postal Code End'),
TRUE
);
In Custom Group Multiple Values Listing the offending line is 90 in
<drupal root>/vendor/civicrm/civicrm-core/ext/legacycustomsearches/CRM/Contact/Form/Search/Custom/MultipleValues.php
$form->add('text', 'sort_name', ts('Contact Name'), TRUE);
I haven't attempted a PR as I get updates via Composer as opposed to using Git, but thought I should report it anyway. It may be that someone is already working on this.