Docs / Inlay / Attribute Settings

Attribute settings

InlayBlock is deliberately an empty marker interface - a block's settings can be declared two different ways, and neither is forced on the other. This page covers declaring a setting directly on the constructor parameter it maps to. See Fluent settings for the alternative, and for repeaters and groups, which attributes can't express.

Field types

| Attribute | Field type | | --- | --- | | Text | Single-line text | | Textarea | Multi-line text | | Richtext | Multi-line text (currently unsanitized HTML if you render it raw - see Current limitations) | | Number | Integer or float | | Toggle | Boolean | | Select | One value from a labeled set (a backed enum, or a literal options array) | | Image | A single uploaded file, hydrated to ImageValue | | Link | Hydrates to LinkValue (label, url, openInNewTab) |

There's no Repeater or Group attribute - a repeatable or grouped item schema has no single constructor parameter to attach to, so those two are fluent-only.

Declaring a setting

use WeArePixel\Inlay\Attributes\Number;
use WeArePixel\Inlay\Attributes\Select;
use WeArePixel\Inlay\Attributes\Text;
use WeArePixel\Inlay\Attributes\Toggle;

final class Hero extends Component implements InlayBlock
{
    public function __construct(
        #[Text(label: 'Heading', maxLength: 80, required: true)]
        public string $heading = 'Welcome',

        #[Toggle(label: 'Show call to action')]
        public bool $showCta = false,

        #[Number(label: 'Columns')]
        public int $columns = 2,

        #[Select(label: 'Image size')]
        public ImageSize $imageSize = ImageSize::Large,
    ) {}

    // ...
}

Every attribute accepts label, help, required, and visibleWhen (an array pair: [fieldName, value] - see Organizing the inspector). Text additionally accepts maxLength; Select additionally accepts options, only needed when the constructor type isn't a backed enum - see Enums.

Constructor defaults are authoritative

For every top-level setting, the constructor parameter's own default value and nullability are the exclusive source of truth:

  • A parameter with a default (public string $heading = 'Welcome') uses that as the setting's default.
  • A nullable parameter with no default (public ?string $subheading = null) is fine too - null is a valid default.
  • A required, non-nullable parameter with no default (public string $heading) fails registration immediately: Block [...] setting [...] has no constructor default and is not nullable. A top-level setting must always be constructible with zero overrides - give it a default or make it nullable. A schema-level default is not permitted to substitute for one here.

There's deliberately no schema-level .default() for a top-level setting - it would create two sources of truth for the same thing. See Fluent settings for the one place .default() is meaningful.

Discovery Call

One call.
We'll both know.

20 minutes 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
  • Trusted by Chemist Warehouse, HelloFresh and Youfoodz
  • Senior engineers only - no juniors on your project
  • Brisbane-based, onshore team

Press Esc to close  ·  B to reopen