Improve init method to support associative array prompt #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Country field prompt not initialized correctly
Problem
When creating or editing contacts in Turba with country fields, the prompt option (e.g., "-- select --") was not being displayed in the dropdown. Instead, the browser was defaulting to the first country option (Afghanistan) when no country was selected, even though the country field configuration specified
'params' => array('prompt' => true).Root Cause
The
Horde_Form_Type_country::init()method was incorrectly extracting thepromptparameter from the$paramsarray. Whencall_user_func_array()is called with an associative array like['prompt' => 1]and the function uses variadic parameters...$params, PHP's behavior with associative arrays means that$paramsitself becomes the associative array (not$params[0]).The original code was trying to access
$params[0], which doesn't exist when an associative array is passed, resulting in$promptbeingnull, and the prompt option never being created.Impact
Solution
Updated
Horde_Form_Type_country::init()to correctly handle associative array parameters:$paramsitself has the'prompt'key (for associative arrays)$params[0]['prompt'](for numeric arrays)$params[0]directly (for direct value passing)This ensures the prompt parameter is correctly extracted regardless of how
call_user_func_array()passes it.Changes
File:
vendor/horde/form/lib/Horde/Form/Type.phpMethod:
Horde_Form_Type_country::init()Testing
Related Issues
This fix ensures that country fields (and potentially other enum fields) properly initialize their prompt options when configured with
'params' => array('prompt' => true)in the attribute configuration.