Flexible Content Fields

Translatable v0.2.0

Example

(new FlexibleContentField('flexible_content'))
    ->addRowSpecs([
        (new FlexibleContentSection('text_row'))
            ->setLabel('Text Row')
            ->addFields([
                TextField::make('title'),
            ]),
        (new FlexibleContentSection('image_row'))
            ->setLabel('Image Row')
            ->addFields([
                ImageUploadField::make('image')
            ]),
        (new FlexibleContentSection('text_image_row'))
            ->setLabel('Text Image Row')
            ->addFields([
                TextField::make('title'),
                ImageUploadField::make('image')
            ]),
    ])

Concept

Flexible Content Fields are a way to attach nested data to JSON attribute on a model. This data is then unpacked and rendered semi-automatically (though customisably) on the frontend.

Updating

Danger!
The structure of a given row must match the structure of the data in the database. E.g. don't replace the ImageUploadField in image_row with a TextField and expect it to work with existing data.

If you need to make changes to row structures you can leave them as they are (to be available to edit) and use ->allownew(false) to prevent adding new rows of that type. Then create a new row type with your desired options. Note: FlexibleContentSection names (e.g. text_row) must be unique but their labels do not.

Usage

Models with Flexible content should have the Yadda\Enso\Crud\Traits\HasFlexibleFields trait in order for the data to be easily output.