You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+85Lines changed: 85 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@
21
21
-[disabling block in select block](#disabling-block-in-select-block)
22
22
-[iframe resizing](#iframe-resizing)
23
23
-[Parameter injection](#parameter-injection)
24
+
-[Global blocks](#global-blocks)
24
25
-[Rendering page builder items on infolist](#rendering-page-builder-items-on-infolist)
25
26
-[Rendering page builder ite previews on fomrms](#rendering-page-builder-ite-previews-on-fomrms)
26
27
-[Customizing actions and button rendering](#customizing-actions-and-button-rendering)
@@ -540,6 +541,90 @@ injections that are provided depends on where this function is used, if this is
540
541
541
542
one thing to note is that because `formatForListingView` uses `formatForSingleView` internally if you wish to inject something in `formatForSingleView` you will need to inject it in `formatForListingView` as well, otherwise it will not work.
542
543
544
+
### Global blocks
545
+
546
+
Global blocks are special blocks that have centralized configuration management. Instead of configuring the same block repeatedly across different pages, you can set up the block configuration once and reuse it everywhere.
547
+
548
+
#### Creating global blocks
549
+
550
+
You can create a global block using the make-block command with the `--global` flag:
- Create a global block class in `app/Filament/{panel}/Blocks/Globals/` directory
558
+
- Automatically generate a Global Blocks resource for centralized management (on first global block creation)
559
+
- Create the necessary database migration for storing global block configurations
560
+
561
+
#### How global blocks work
562
+
563
+
Global blocks use the `IsGlobalBlock` trait and have two key methods:
564
+
565
+
```php
566
+
<?php
567
+
568
+
use Redberry\PageBuilderPlugin\Traits\IsGlobalBlock;
569
+
570
+
class ContactForm extends BaseBlock
571
+
{
572
+
use IsGlobalBlock;
573
+
574
+
// Define the block's schema - this will be used in the Global Blocks resource
575
+
public static function getBaseBlockSchema(?object $record = null): array
576
+
{
577
+
return [
578
+
TextInput::make('title')->required(),
579
+
Textarea::make('description'),
580
+
TextInput::make('email')->email(),
581
+
];
582
+
}
583
+
584
+
// The schema returned to the page builder (empty for global blocks)
585
+
public static function getBlockSchema(?object $record = null): array
586
+
{
587
+
$schema = static::getBaseBlockSchema($record);
588
+
return static::applyGlobalConfiguration($schema);
589
+
}
590
+
}
591
+
```
592
+
593
+
#### Global Blocks resource
594
+
595
+
When you create your first global block, a "Global Blocks" resource is automatically generated in your Filament admin panel. This resource allows you to:
596
+
597
+
- View all available global blocks
598
+
- Configure each block's field values
599
+
- Edit configurations using the actual Filament form fields defined in `getBaseBlockSchema()`
600
+
601
+
602
+
#### Using global blocks on pages
603
+
604
+
When adding global blocks to pages:
605
+
-**No configuration modal appears** - blocks are added instantly
606
+
-**No per-page configuration** - all configuration is managed centrally
607
+
-**Consistent values everywhere** - the block uses the same configured values across all pages
608
+
609
+
Simply add your global block to the page builder's blocks array:
610
+
611
+
```php
612
+
<?php
613
+
614
+
PageBuilder::make('website_content')
615
+
->blocks([
616
+
ContactForm::class,
617
+
// other blocks...
618
+
]);
619
+
```
620
+
621
+
#### Key benefits
622
+
623
+
-**Centralized management**: Configure once, use everywhere
624
+
-**Consistency**: Same content and styling across all instances
625
+
-**Efficiency**: No need to reconfigure the same block on multiple pages
626
+
-**Maintainability**: Update global block configuration in one place
627
+
543
628
### Rendering page builder items on infolist
544
629
outside of form you might want to render page builder items on infolist, for this we provide two prebuilt entries:
0 commit comments