PHP code example of awcodes / mason
1. Go to this page and download the library: Download awcodes/mason library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
awcodes / mason example snippets
return [
'generator' => [
'namespace' => 'App\\Mason',
'views_path' => 'mason',
],
'preview' => [
'layout' => 'mason::iframe-preview',
],
'entry' => [
'layout' => 'mason::iframe-entry',
],
'routes' => [
'middleware' => ['web', 'auth'],
],
];
'routes' => [
'middleware' => ['web', 'auth:admin'],
],
use Awcodes\Mason\Mason;
use Awcodes\Mason\Bricks\Section;
->schema([
Mason::make('content')
->bricks([
Section::class,
]),
])
Mason::make('content')
->previewLayout('layouts.mason-preview') // your app's layout
->bricks([...])
Mason::make('content')
->doubleClickToEdit()
->bricks([...])
use Awcodes\Mason\MasonEntry;
use Awcodes\Mason\Bricks\Section;
->schema([
MasonEntry::make('content')
->bricks([
Section::class,
]),
])
MasonEntry::make('content')
->previewLayout('layouts.mason-entry')
->bricks([...])
Mason::make('content')
->extraInputAttributes(['style' => 'min-height: 30rem;'])
->bricks([...])
MasonEntry::make('content')
->extraInputAttributes(['style' => 'min-height: 40rem;'])
->bricks([...])
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())
use Awcodes\Mason\Enums\SidebarPosition;
Mason::make('content')
->sidebarPosition(SidebarPosition::Start)
->bricks([...])
Mason::make('content')
->displayActionsAsGrid()
->bricks([...])
// Sort ascending (A-Z) by label
Mason::make('content')
->sortBricks('asc')
->bricks([...])
// Or simply (defaults to 'asc')
Mason::make('content')
->sortBricks()
->bricks([...])
// Sort descending (Z-A) by label
Mason::make('content')
->sortBricks('desc')
->bricks([...])
public static function toHtml(array $config, ?array $data = null): ?string
{
return view('mason.static-brick');
}
public static function configureBrickAction(Action $action): Action
{
return $action->modalHidden();
}
Mason::make('content')
->colorModeToggle()
->defaultColorMode('dark')
->bricks([...])
use Awcodes\Mason\Brick;
use Filament\Actions\Action;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\ToggleButtons;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section as FilamentSection;
use Filament\Support\Icons\Heroicon;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HtmlString;
use Throwable;
class Section extends Brick
{
public static function getId(): string
{
return 'section';
}
public static function getLabel(): string
{
return parent::getLabel();
}
public static function getIcon(): string | Heroicon | Htmlable | null
{
return new HtmlString('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 20h.01M4 20h.01M8 20h.01M12 20h.01M16 20h.01M20 4h.01M4 4h.01M8 4h.01M12 4h.01M16 4v.01M4 9a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1z"/></svg>');
}
/**
* @throws Throwable
*/
public static function toHtml(array $config, ?array $data = null): ?string
{
return view('mason::bricks.section.index', [
'background_color' => $config['background_color'] ?? 'white',
'image' => $config['image'] ?? null,
'text' => $config['text'] ?? null,
])->render();
}
public static function configureBrickAction(Action $action): Action
{
return $action
->slideOver()
->schema([
Radio::make('background_color'),
FileUpload::make('image'),
RichEditor::make('text'),
]);
}
}
{!! mason(content: $post->content, bricks: \App\Mason\BrickCollection::make())->toHtml() !!}
use Awcodes\Mason\Support\MasonRenderer;
$renderer = MasonRenderer::make($content)->bricks(\App\Mason\BrickCollection::make());
$renderer->toHtml()
$renderer->toUnsafeHtml();
$renderer->toArray();
$renderer->toText();
use Awcodes\Mason\Support\Faker;
Faker::make()
->brick(
id: 'section',
config: [
'background_color' => 'white',
'text' => '<h2>This is a heading</h2><p>Just some random text for a paragraph</p>',
'image' => null,
]
)
->brick(
id: 'section',
config: [
'background_color' => 'primary',
'text' => '<h2>This is a heading</h2><p>Just some random text for a paragraph</p>',
'image' => null,
]
)
->asJson(),
bash
php artisan vendor:publish --tag="mason-config"
bash
php artisan make:mason-brick Section