acf-builder
acf-builder copied to clipboard
feat: Enhance ChoiceFieldBuilder to support numeric choice keys
This PR fixes a bug in the ChoiceFieldBuilder::addChoices() method that prevented us from setting explicit numeric keys without resulting to passing a choice as a Associative array.
The refactored code correctly handles all choice formats:
- Indexed arrays: ['red', 'blue'] → 'red' => 'red', 'blue' => 'blue'
- Associative arrays: ['yes' => 'Yes, please...'] → 'yes' => 'Yes, please...'
- Nested arrays: [['blue' => 'Blue']] → 'blue' => 'Blue'
- Numeric keys: [1 => 'one', 100 => 'one hundred'] → preserved as-is
Added an additional test to test the new supported format as well.
Fixes #125 at least with the numeric keys.