Row Specs
It is often convenient to define a row spec as its own class so that it can be included in multiple places. These are usually kept in App\Crud\RowSpecs\ but you can put them wherever you like.
<?php
namespace App\Crud\RowSpecs;
use Yadda\Enso\Crud\Forms\Fields\TextField;
class Button extends FlexibleContentSection
{
public function __construct(string $name = 'main')
{
parent::__construct($name);
$this->setLabel('Button')->addFields([
(new TextField('url'))
->addFieldsetClass('is-half'),
(new TextField('label'))
->addFieldsetClass('is-half'),
]);
}
}
Manipulating existing Row Specs
You may need to extend an existing FlexibleContentSection that has some settings already defined. You may need to add Rowspecs in a certain order, at a certain point in the current list.
$flexible_content_field
->addRowSpecAfter('name_of_target_row_spec', TextSection::make('text'))
->addRowSpecsAfter('other_target', [
WysiwygSection::make('wysiwyg'),
ImageSection::make('images'),
]);
The following example will remove a row spec named a, then add a new row spec as the first element.
$flexible_content_field
->removeRowSpec('a')
->prependRowSpec(TextSection::make('text'));
Instead of removing or adding row specs, you may wish to re-order them if some settings are more important, or to assign new labels and order them alphabetically moveRowSpecBefore or moveRowSpecAfter.
$flexible_content_field->moveRowSpecAfter(
'name_of_field_to_move',
'name_of_field_to_insert_after'
);