Per-slug Fields

You can add extra fields that will only be displayed when editing specific items.

Limitations

Fields will only be visible after the item is saved - the slug must exist when the item is loaded for the fields to be loaded.

Setup

This example will add a WyswiygField to the item with the slug 'home'.

public function addHomeFields() {
    $form = $this->getEditForm();

    $form->addSections([
        (new JsonDataSection('data'))
            ->setLabel('My Extra Data')
            ->addFields([
                (new WysiwygField('my_extra_text_field')),
            ]),
    ]);

    return $form;
}
  • Method Name The method name must begin with add and end with fields with the slug of the item, in Studly Case, in between.
  • Section Name In the example above the 'data' passed to getSectionByName corresponds to the name of the JSON column that the data will be stored on. data should exist on your Crud's table by default but this means you can add extra columns if need be.