Skip to content

fix(format-spec): read every option shape a select can be written in - #50

Merged
sylvesterdamgaard merged 1 commit into
cboxdk:mainfrom
Orange-Hotel-Marketing:fix/select-option-formats
Sep 9, 2026
Merged

sylvesterdamgaard merged 1 commit into
cboxdk:mainfrom
Orange-Hotel-Marketing:fix/select-option-formats

Conversation

@JorisOrangeStudio

Copy link
Copy Markdown
Contributor

Description

selectSpec() handled two of the three option shapes Statamic accepts: a key => label map and a flat list of scalars. It missed the list of ['key' => ..., 'value' => ...] maps, which is what the Control Panel writes and therefore the common one in practice. Those entries are arrays under numeric keys, so the is_scalar filter dropped them all and allowed_values came back empty.

Mirrors Fieldtypes\HasSelectOptions::getOptions() so all three shapes resolve.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🔧 Tool enhancement
  • 📝 Documentation
  • ♻️ Refactoring

Related Issue

None. Found writing a page-builder entry, where every select and button_group in the blueprint reported "allowed_values": [] while the field config alongside it carried the options in full.

Testing

  • Tests pass (composer test)
  • Code quality checks pass (composer quality)
  • Tested manually with Statamic

tests/Unit/FieldFormatSpecTest.php — 6 cases: each of the three shapes, a non-string key cast to string, a select with no options, and enum_array still reported for a multiple select.

Verified against main: 3 of the 6 fail there, all pass here. The other 3 are regression guards for the two shapes that already worked.

Full gate green — pint, PHPStan level 9, 1112 tests / 5611 assertions.

Environment

  • Statamic: v6.31.0
  • Laravel: v13.30.1
  • PHP: 8.4.25

Checklist

  • My code follows the project style
  • I've added/updated tests if needed
  • Tool responses follow the standard format

Notes

The effect is worse than one empty array: a client sees a field it knows is an enum with nothing to choose from, so it either guesses or omits the field. On a select driving a template branch, omitting it renders nothing, and the write still reports success.

Two things deliberately left out of scope. cast_booleans selects store real booleans rather than the string values reported here, which the spec does not yet express. And the option labels are dropped, though they would help a client choose between values it cannot otherwise interpret.

selectSpec() handled two of the three shapes Statamic accepts: a
key => label map and a flat list of scalars. It missed the list of
['key' => ..., 'value' => ...] maps, which is what the Control Panel
writes and therefore the common one in practice. Those entries are arrays
under numeric keys, so the is_scalar filter dropped them all and
allowed_values came back empty.

A client reading the spec then sees a field it knows is an enum, with no
values to choose from, and has to guess or fall back to include_config.
Mirror Fieldtypes\HasSelectOptions::getOptions() so all three shapes
resolve, including selects, radios and button groups.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants