aw codes icon logo
Docs Hub

Search across every project.

Mason Switch project

A simple block based drag and drop page / document builder field for Filament.

3.x Current

On this page

Organizing bricks

Reusable collections

Both the field and the entry need the same brick list, and repeating it invites them to drift apart. Put it in one place:

class BrickCollection
{
    public static function make(): array
    {
        return [
            NewsletterSignup::class,
            Section::class,
            Cards::class,
            SupportCenter::class,
        ];
    }
}
Mason::make('content')->bricks(BrickCollection::make());

MasonEntry::make('content')->bricks(BrickCollection::make());

The same list is what the renderer needs on the front end, so a collection keeps all three in step.

Groups

Wrap bricks in a BrickGroup to label and collapse them in the sidebar. Searching by name or tag expands any group holding a match.

use Awcodes\Mason\BrickGroup;

Mason::make('content')
    ->bricks([
        BrickGroup::make('Content')
            ->bricks([
                Section::class,
                Grid::class,
            ]),
        BrickGroup::make('Marketing')
            ->bricks([
                Hero::class,
                CallToAction::class,
            ]),
        LeadForm::class,
    ]);

Groups and standalone bricks can be mixed freely in the same array, as LeadForm shows.

Sorting

Bricks appear in the order you declare them. To sort by label instead:

Mason::make('content')
    ->sortBricks()         // 'asc' by default
    ->bricks([...]);

Mason::make('content')
    ->sortBricks('desc')
    ->bricks([...]);

Sorting applies to the top-level array, so groups are sorted alongside standalone bricks by their respective labels — it does not reorder bricks inside a group.