Skip to content

Commit a727f1c

Browse files
committed
feat: add configurable discovery paths for global blocks
1 parent d097ab2 commit a727f1c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

config/page-builder-plugin.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
'block_model_class' => Redberry\PageBuilderPlugin\Models\PageBuilderBlock::class,
55

66
'polymorphic_relationship_name' => 'page_builder_blockable',
7+
8+
'global_blocks_discovery_paths' => [
9+
'app/Filament/*/Blocks/Globals',
10+
'app/Filament/Blocks/Globals',
11+
],
712
];

src/Models/GlobalBlockConfig.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,24 @@ protected static function discoverGlobalBlocks(): array
8989
$globalBlocks = [];
9090
$appPath = app_path();
9191

92-
$globalsDirectories = File::glob($appPath . '/Filament/*/Blocks/Globals');
92+
$discoveryPaths = config('page-builder-plugin.global_blocks_discovery_paths', [
93+
'app/Filament/*/Blocks/Globals',
94+
]);
95+
96+
$globalsDirectories = [];
97+
98+
foreach ($discoveryPaths as $pattern) {
99+
$fullPattern = $appPath . '/' . ltrim($pattern, 'app/');
100+
101+
if (str_contains($pattern, '*')) {
102+
$directories = File::glob($fullPattern);
103+
$globalsDirectories = array_merge($globalsDirectories, $directories);
104+
} else {
105+
if (File::isDirectory($fullPattern)) {
106+
$globalsDirectories[] = $fullPattern;
107+
}
108+
}
109+
}
93110

94111
foreach ($globalsDirectories as $directory) {
95112
$files = File::glob($directory . '/*.php');

0 commit comments

Comments
 (0)