acf-builder icon indicating copy to clipboard operation
acf-builder copied to clipboard

feat: Enhance ChoiceFieldBuilder to support numeric choice keys

Open Levdbas opened this issue 6 months ago • 0 comments

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.

Levdbas avatar Jul 11 '25 04:07 Levdbas