Flexible Content Settings

Translatable v0.2.121

You can add extra, hidden fields to Flexible Content Rows. When these are added a cog icon will be displayed on the Flexible Content row which, when clicked, will switch between showing regular fields and settings fields.

Settings fields are the same as regular fields, you just add them with a different method:

FlexibleContentSection::make('wysiwyg')
    ->addFields([
        WysiwygField::make('wysiwyg'),
    ])
    ->addSettingsFields([
        CheckboxField::make('hidden')
            ->setLabel('This is the label')
            ->setOptions([
                'hidden' => 'Hidden',
            ])
            ->setDefaultValue(0),
    ]),

Defaults

You might have noticed that I used hidden with a default of 0 in the above example instead of visible with a default of 1. This is because when you add a field to an existing row its default value will not be added to the data in the database and the default value will not be used on when accessing the data on the front end - it will only be used when creating new rows. Because of this it is often safer and/or easier to use a value that setting whose default is falsy.

Manipulating existing settings

You may need to extend an existing FlexibleContentSection that has some settings already defined. The following example will remove a setting, then add a new setting as the first element.

$flexible_content_section
    ->removeSettingsField('a')
    ->prependSetting(TextField::make('b'));

Instead of removing or adding settings, you may wish to re-order them if some settings are more important and need greater prominence using moveSettingsFieldBefore or moveSettingsFieldAfter.

$flexible_content_section->moveSettingsFieldAfter(
    'name_of_field_to_move',
    'name_of_field_to_insert_after'
);