Skip to content

Commit 43a6b04

Browse files
committed
feat: add configuration options to global block resource
1 parent 5f6130e commit 43a6b04

File tree

5 files changed

+117
-4
lines changed

5 files changed

+117
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,20 @@ You can configure the plugin directly when registering it:
590590
->plugins([
591591
\Redberry\PageBuilderPlugin\GlobalBlocksPlugin::make()
592592
->enableGlobalBlocks(true) // Enable/disable the Global Blocks resource
593-
->resource(\App\Filament\Resources\CustomGlobalBlocksResource::class), // Use custom resource
593+
->resource(\App\Filament\Resources\CustomGlobalBlocksResource::class) // Use custom resource
594+
->navigationGroup('Content Management') // Customize navigation group
595+
->navigationSort(10) // Set navigation sort order
596+
->navigationIcon('heroicon-o-document-text'), // Set navigation icon (use empty string '' to remove icon)
594597
// ... other plugins
595598
])
596599
```
597600

598601
**Configuration options:**
599602
- `enableGlobalBlocks(bool)`: Enable or disable the Global Blocks resource (default: `true`)
600603
- `resource(string)`: Specify a custom resource class that extends the package's resource
604+
- `navigationGroup(string)`: Set the navigation group for the Global Blocks resource (default: `'Content Management'`)
605+
- `navigationSort(int)`: Set the navigation sort order for the Global Blocks resource
606+
- `navigationIcon(string)`: Set the navigation icon for the Global Blocks resource (use empty string `''` to remove the icon)
601607

602608
This approach allows you to:
603609
- **Enable Global Blocks on specific panels only** - Perfect for multi-panel applications

resources/views/forms/page-builder.blade.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
$editAction = $getAction($getEditActionName());
2525
$editAction = $editAction(['item' => $item, 'index' => $loop->index]);
2626
$editActionIsVisible = $editAction->isVisible();
27+
28+
$blockType = $item['block_type'] ?? null;
29+
$isGlobalBlock = $blockType &&
30+
class_exists($blockType) &&
31+
method_exists($blockType, 'isGlobalBlock') &&
32+
$blockType::isGlobalBlock();
2733
@endphp
2834
<li x-sortable-item="{{ $item['id'] }}"
2935
class="fi-fo-repeater-item divide-y divide-gray-100 rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:divide-white/10 dark:bg-white/5 dark:ring-white/10">
@@ -34,12 +40,18 @@ class="fi-fo-repeater-item divide-y divide-gray-100 rounded-xl bg-white shadow-s
3440
<div class="flex justify-between w-full items-center">
3541
{{ $getBlockLabel($item['block_type'], $item, $loop->index) }}
3642
<div class="flex gap-x-4 items-center">
43+
@if ($editActionIsVisible)
44+
@if ($isGlobalBlock)
45+
<div class="px-3 py-2">
46+
<x-heroicon-o-globe-alt class="h-5 w-5 text-white"/>
47+
</div>
48+
@else
49+
{{ $renderEditActionButton($item['id'], $loop->index) }}
50+
@endif
51+
@endif
3752
@if ($deleteActionIsVisible)
3853
{{ $renderDeleteActionButton($item['id'], $loop->index) }}
3954
@endif
40-
@if ($editActionIsVisible)
41-
{{ $renderEditActionButton($item['id'], $loop->index) }}
42-
@endif
4355
</div>
4456
</div>
4557
</div>

src/GlobalBlocksPlugin.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ class GlobalBlocksPlugin implements Plugin
1212

1313
protected string $globalResourceClass = GlobalBlockConfigResource::class;
1414

15+
protected ?string $navigationGroup = null;
16+
17+
protected ?int $navigationSort = null;
18+
19+
protected ?string $navigationIcon = null;
20+
1521
public static function make(): static
1622
{
1723
return app(static::class);
@@ -31,6 +37,27 @@ public function resource(string $resourceClass): static
3137
return $this;
3238
}
3339

40+
public function navigationGroup(string $group): static
41+
{
42+
$this->navigationGroup = $group;
43+
44+
return $this;
45+
}
46+
47+
public function navigationSort(int $sort): static
48+
{
49+
$this->navigationSort = $sort;
50+
51+
return $this;
52+
}
53+
54+
public function navigationIcon(string $icon): static
55+
{
56+
$this->navigationIcon = $icon;
57+
58+
return $this;
59+
}
60+
3461
public function getId(): string
3562
{
3663
return 'page-builder-global-blocks';
@@ -46,6 +73,18 @@ public function register(Panel $panel): void
4673
return;
4774
}
4875

76+
if ($this->navigationGroup !== null) {
77+
$this->globalResourceClass::navigationGroup($this->navigationGroup);
78+
}
79+
80+
if ($this->navigationSort !== null) {
81+
$this->globalResourceClass::navigationSort($this->navigationSort);
82+
}
83+
84+
if ($this->navigationIcon !== null) {
85+
$this->globalResourceClass::navigationIcon($this->navigationIcon);
86+
}
87+
4988
$panel->resources([
5089
$this->globalResourceClass,
5190
]);

src/Resources/GlobalBlockConfigResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class GlobalBlockConfigResource extends Resource
2020

2121
protected static ?string $navigationGroup = 'Content Management';
2222

23+
protected static ?int $navigationSort = null;
24+
2325
protected static ?string $navigationLabel = 'Global Blocks';
2426

2527
protected static ?string $modelLabel = 'Global Block';

tests/GlobalBlocksPluginTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,57 @@
7676

7777
expect($panel->getResources())->toBeEmpty();
7878
});
79+
80+
it('can configure navigation group', function () {
81+
$plugin = GlobalBlocksPlugin::make()
82+
->navigationGroup('Custom Group');
83+
84+
expect($plugin)->toBeInstanceOf(GlobalBlocksPlugin::class);
85+
});
86+
87+
it('can configure navigation sort', function () {
88+
$plugin = GlobalBlocksPlugin::make()
89+
->navigationSort(15);
90+
91+
expect($plugin)->toBeInstanceOf(GlobalBlocksPlugin::class);
92+
});
93+
94+
it('can configure navigation icon', function () {
95+
$plugin = GlobalBlocksPlugin::make()
96+
->navigationIcon('heroicon-o-document-text');
97+
98+
expect($plugin)->toBeInstanceOf(GlobalBlocksPlugin::class);
99+
});
100+
101+
it('can remove navigation icon with empty string', function () {
102+
$plugin = GlobalBlocksPlugin::make()
103+
->navigationIcon('');
104+
105+
expect($plugin)->toBeInstanceOf(GlobalBlocksPlugin::class);
106+
});
107+
108+
it('applies navigation customizations to resource', function () {
109+
$panel = Panel::make();
110+
111+
$plugin = GlobalBlocksPlugin::make()
112+
->navigationGroup('Custom Group')
113+
->navigationSort(25)
114+
->navigationIcon('heroicon-o-cog');
115+
116+
$plugin->register($panel);
117+
118+
expect(GlobalBlockConfigResource::getNavigationGroup())->toBe('Custom Group');
119+
expect(GlobalBlockConfigResource::getNavigationSort())->toBe(25);
120+
expect(GlobalBlockConfigResource::getNavigationIcon())->toBe('heroicon-o-cog');
121+
});
122+
123+
it('applies empty icon to resource', function () {
124+
$panel = Panel::make();
125+
126+
$plugin = GlobalBlocksPlugin::make()
127+
->navigationIcon('');
128+
129+
$plugin->register($panel);
130+
131+
expect(GlobalBlockConfigResource::getNavigationIcon())->toBe('');
132+
});

0 commit comments

Comments
 (0)