Docs / Inlay / Enums

Enums

A Select setting typed as a PHP backed enum derives its options automatically - you don't hand-write an options array:

enum ImageSize: string { case Small = 'small'; case Large = 'large'; }

The stored value is always the enum's scalar value; the enum case is hydrated back before your component is constructed, and the package validates that a stored value corresponds to a real case.

Custom labels

By default an option's label is Str::headline($case->name). Implement WearePixel\Inlay\Support\SettingOptions for a custom one:

enum ImageSize: string implements \WearePixel\Inlay\Support\SettingOptions { case Small = 'small'; case Large = 'large'; public function label(): string { return match ($this) { self::Small => 'Small (400px)', self::Large => 'Large (1200px)', }; } }

Option descriptions

Implement WearePixel\Inlay\Support\DescribesSettingOptions as well - it's an independent interface, so adding it is never a breaking change for a case that already implements SettingOptions - to show a short explanatory description under the field once that option is selected:

enum ImageSize: string implements \WearePixel\Inlay\Support\SettingOptions, \WearePixel\Inlay\Support\DescribesSettingOptions { case Small = 'small'; case Large = 'large'; public function label(): string { /* ... */ } public function optionDescription(): ?string { return match ($this) { self::Small => null, self::Large => 'Full-width, best for a strong first impression.', }; } }

Mismatched options

If you declare ->options(ImageSize::class) fluently and the constructor parameter is typed as a different enum, registration fails: Component [...] setting [...] declares options for [...], but the constructor expects [...].

Orphaned values

An orphaned stored value - a case removed from the enum after content was authored against it - falls back to the constructor default and logs a warning, uniformly across public rendering, the admin editor, and publishing. There's currently no separate, more visible admin-facing warning, and no publish-time block for this case - see Current limitations.

Discovery Call

One call.
We'll both know.

An hour to walk through your project, ask the hard questions, and work out honestly if we're the right team for it.

  • One call per day - it gets our full attention
  • Australia's only Laravel Premier Partner
  • Senior engineers only - no juniors on your project
  • Brisbane-based, onshore team

Press Esc to close  ·  B to reopen