Skip to content

Commit dee28d0

Browse files
committed
Some page resource fields can be disabled
Add hero CTA repeater
1 parent 417d480 commit dee28d0

File tree

5 files changed

+108
-31
lines changed

5 files changed

+108
-31
lines changed

config/filament-flexible-content-block-pages.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
FilamentFlexibleContentBlockPagesConfig::TYPE_MENU => \Statikbe\FilamentFlexibleContentBlockPages\Resources\MenuResource::class,
4747
],
4848

49+
'page_resource' => [
50+
\Statikbe\FilamentFlexibleContentBlockPages\Models\Page::class => [
51+
'enable_hero_call_to_actions' => true,
52+
'enable_author' => true,
53+
'enable_parent' => true,
54+
'enable_undeletable' => true,
55+
],
56+
// If you extend PageResource and want to use your own model, you can add your the extended page resource config for your own model here...
57+
],
58+
4959
'panel' => [
5060
'path' => 'admin/website',
5161
'middleware' => [
@@ -76,10 +86,6 @@
7686
],
7787
],
7888

79-
'seo' => [
80-
'default_canonical_locale' => 'nl',
81-
],
82-
8389
'route_helper' => \Statikbe\FilamentFlexibleContentBlockPages\Routes\LocalisedPageRouteHelper::class,
8490

8591
/*
@@ -129,6 +135,7 @@
129135

130136
'sitemap' => [
131137
'enabled' => true,
138+
'default_canonical_locale' => 'nl',
132139
'generator_service' => \Statikbe\FilamentFlexibleContentBlockPages\Services\SitemapGeneratorService::class,
133140
'method' => SitemapGeneratorMethod::MANUAL,
134141
'include_pages' => true,

database/migrations/create_filament_flexible_content_block_pages_table.php.stub

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ return new class extends Migration
1010
public function up()
1111
{
1212
$pageTable = FilamentFlexibleContentBlockPages::config()->getPagesTable();
13+
$pageModel = FilamentFlexibleContentBlockPages::config()->getPageModel()::class;
1314

14-
Schema::create($pageTable, function (Blueprint $table) use ($pageTable) {
15+
Schema::create($pageTable, function (Blueprint $table) use ($pageTable, $pageModel) {
1516
$table->id();
1617

1718
$table->json('title');
@@ -25,6 +26,10 @@ return new class extends Migration
2526
->nullable();
2627
$table->json('hero_image_title')
2728
->nullable();
29+
if(FilamentFlexibleContentBlockPages::config()->isHeroCallToActionsEnabled($pageModel)) {
30+
$table->json('hero_call_to_actions')
31+
->nullable();
32+
}
2833

2934
//Publishing:
3035
$table->timestamp('publishing_begins_at')
@@ -62,24 +67,30 @@ return new class extends Migration
6267
->unique();
6368

6469
//Author:
65-
$table->unsignedBigInteger('author_id')
66-
->nullable();
67-
$table->foreign('author_id')
68-
->references('id')
69-
->on(FilamentFlexibleContentBlockPages::config()->getAuthorsTable())
70-
->onDelete('set null');
70+
if(FilamentFlexibleContentBlockPages::config()->isAuthorEnabled($pageModel)) {
71+
$table->unsignedBigInteger('author_id')
72+
->nullable();
73+
$table->foreign('author_id')
74+
->references('id')
75+
->on(FilamentFlexibleContentBlockPages::config()->getAuthorsTable())
76+
->onDelete('set null');
77+
}
7178

7279
// Parent-child:
73-
$table->unsignedBigInteger('parent_id')
74-
->nullable();
75-
$table->foreign('parent_id')
76-
->references('id')
77-
->on($pageTable)
78-
->onDelete('set null');
80+
if(FilamentFlexibleContentBlockPages::config()->isParentEnabled($pageModel)) {
81+
$table->unsignedBigInteger('parent_id')
82+
->nullable();
83+
$table->foreign('parent_id')
84+
->references('id')
85+
->on($pageTable)
86+
->onDelete('set null');
87+
}
7988

8089
// Deletable:
81-
$table->boolean('is_undeletable')
82-
->default(false);
90+
if(FilamentFlexibleContentBlockPages::config()->isUndeletableEnabled($pageModel)) {
91+
$table->boolean('is_undeletable')
92+
->default(false);
93+
}
8394

8495
$table->timestamps();
8596
});

src/FilamentFlexibleContentBlockPagesConfig.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Statikbe\FilamentFlexibleContentBlockPages;
44

55
use Filament\Resources\Resource;
6+
use Illuminate\Database\Eloquent\Model;
67
use Statikbe\FilamentFlexibleContentBlockPages\Models\Menu;
78
use Statikbe\FilamentFlexibleContentBlockPages\Models\MenuItem;
89
use Statikbe\FilamentFlexibleContentBlockPages\Models\Page;
@@ -220,7 +221,7 @@ public function getPanelAuthMiddleware(): array
220221

221222
public function getSEODefaultCanonicalLocale(): string
222223
{
223-
return $this->packageConfig('seo.default_canonical_locale', 'en');
224+
return $this->packageConfig('sitemap.default_canonical_locale', 'en');
224225
}
225226

226227
public function getRouteHelper(): HandlesPageRoutes
@@ -300,6 +301,42 @@ public function getSitemapCustomUrls(): array
300301
return $this->packageConfig('sitemap.custom_urls', []);
301302
}
302303

304+
/**
305+
* @param class-string<Model> $modelClass
306+
* @return bool
307+
*/
308+
public function isHeroCallToActionsEnabled(string $modelClass): bool
309+
{
310+
return $this->packageConfig("page_resource.{$modelClass}.enable_hero_call_to_actions", true);
311+
}
312+
313+
/**
314+
* @param class-string<Model> $modelClass
315+
* @return bool
316+
*/
317+
public function isAuthorEnabled(string $modelClass): bool
318+
{
319+
return $this->packageConfig("page_resource.{$modelClass}.enable_author", true);
320+
}
321+
322+
/**
323+
* @param class-string<Model> $modelClass
324+
* @return bool
325+
*/
326+
public function isParentEnabled(string $modelClass): bool
327+
{
328+
return $this->packageConfig("page_resource.{$modelClass}.enable_parent", true);
329+
}
330+
331+
/**
332+
* @param class-string<Model> $modelClass
333+
* @return bool
334+
*/
335+
public function isUndeletableEnabled(string $modelClass): bool
336+
{
337+
return $this->packageConfig("page_resource.{$modelClass}.enable_undeletable", true);
338+
}
339+
303340
private function packageConfig(string $configKey, $default = null): mixed
304341
{
305342
return config('filament-flexible-content-block-pages.'.$configKey, $default);

src/Models/Page.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function isHomePage(): bool
8181

8282
public function isDeletable(): bool
8383
{
84+
if(!$this->hasAttribute('is_undeletable')){
85+
return true;
86+
}
87+
8488
// TODO improve once the authorisation is implemented:
8589
return ! $this->is_undeletable;
8690
}

src/Resources/PageResource.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Statikbe\FilamentFlexibleContentBlocks\Filament\Form\Fields\AuthorField;
2121
use Statikbe\FilamentFlexibleContentBlocks\Filament\Form\Fields\CodeField;
2222
use Statikbe\FilamentFlexibleContentBlocks\Filament\Form\Fields\ContentBlocksField;
23+
use Statikbe\FilamentFlexibleContentBlocks\Filament\Form\Fields\Groups\HeroCallToActionSection;
2324
use Statikbe\FilamentFlexibleContentBlocks\Filament\Form\Fields\Groups\HeroImageSection;
2425
use Statikbe\FilamentFlexibleContentBlocks\Filament\Form\Fields\Groups\OverviewFields;
2526
use Statikbe\FilamentFlexibleContentBlocks\Filament\Form\Fields\Groups\PublicationSection;
@@ -104,11 +105,17 @@ public static function form(Form $form): Form
104105

105106
protected static function getGeneralTabFields(): array
106107
{
107-
return [
108+
$fields = [
108109
TitleField::create(true),
109110
IntroField::create(),
110111
HeroImageSection::create(true),
111112
];
113+
114+
if(FilamentFlexibleContentBlockPages::config()->isHeroCallToActionsEnabled(static::getModel())){
115+
$fields[] = new HeroCallToActionSection();
116+
}
117+
118+
return $fields;
112119
}
113120

114121
protected static function getContentTabFields(): array
@@ -135,20 +142,31 @@ protected static function getOverviewTabFields(): array
135142

136143
protected static function getAdvancedTabFields(): array
137144
{
138-
return [
145+
$config = FilamentFlexibleContentBlockPages::config();
146+
$modelClass = static::getModel();
147+
148+
$fields = [
139149
PublicationSection::create(),
140-
// TODO feature flag
141150
CodeField::create(),
142151
SlugField::create(false),
143-
Grid::make()
144-
->schema([
145-
// TODO feature flag
146-
AuthorField::create(),
147-
// TODO feature flag
148-
ParentField::create()
149-
->searchable(['title', 'code', 'slug', 'intro']),
150-
]),
151152
];
153+
154+
$gridFields = [];
155+
156+
if ($config->isAuthorEnabled($modelClass)) {
157+
$gridFields[] = AuthorField::create();
158+
}
159+
160+
if ($config->isParentEnabled($modelClass)) {
161+
$gridFields[] = ParentField::create()
162+
->searchable(['title', 'code', 'slug', 'intro']);
163+
}
164+
165+
if (!empty($gridFields)) {
166+
$fields[] = Grid::make()->schema($gridFields);
167+
}
168+
169+
return $fields;
152170
}
153171

154172
public static function table(Table $table): Table

0 commit comments

Comments
 (0)