Skip to content

Commit 555a409

Browse files
committed
Morph map
1 parent ce0b8a1 commit 555a409

File tree

8 files changed

+44
-1
lines changed

8 files changed

+44
-1
lines changed

src/FilamentFlexibleContentBlockPagesConfig.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ public function getCustomPageTemplate(string $code): ?string
170170
return $this->getCustomPageTemplates()[$code] ?? null;
171171
}
172172

173+
public function getMorphMap(): array
174+
{
175+
return [
176+
$this->getPageModel()->getMorphClass() => $this->getPageModel()::class,
177+
$this->getSettingsModel()->getMorphClass() => $this->getSettingsModel()::class,
178+
$this->getTagModel()->getMorphClass() => $this->getTagModel()::class,
179+
$this->getTagTypeModel()->getMorphClass() => $this->getTagTypeModel()::class,
180+
$this->getRedirectModel()->getMorphClass() => $this->getRedirectModel()::class,
181+
];
182+
}
183+
173184
private function packageConfig(string $configKey, $default = null): mixed
174185
{
175186
return config('filament-flexible-content-block-pages.'.$configKey, $default);

src/FilamentFlexibleContentBlockPagesServiceProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Statikbe\FilamentFlexibleContentBlockPages;
44

5+
use Illuminate\Database\Eloquent\Relations\Relation;
56
use Spatie\LaravelPackageTools\Package;
67
use Spatie\LaravelPackageTools\PackageServiceProvider;
8+
use Statik\LaravelLeisure\LaravelLeisure;
79
use Statikbe\FilamentFlexibleContentBlockPages\Commands\SeedDefaultsCommand;
810
use Statikbe\FilamentFlexibleContentBlockPages\Components\BaseLayout;
911
use Statikbe\FilamentFlexibleContentBlockPages\Components\LanguageSwitch;
@@ -34,4 +36,10 @@ public function configurePackage(Package $package): void
3436
BaseLayout::class,
3537
);
3638
}
39+
40+
public function packageBooted()
41+
{
42+
// add morph map
43+
Relation::morphMap(\Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages::config()->getMorphMap());;
44+
}
3745
}

src/Models/Page.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,9 @@ public function isDeletable(): bool
8383
// TODO improve once the authorisation is implemented:
8484
return ! $this->is_undeletable;
8585
}
86+
87+
public function getMorphClass()
88+
{
89+
return 'filament-flexible-content-block-pages::page';
90+
}
8691
}

src/Models/Redirect.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ public static function getDirectionMap(): array
5656
// Merge both values
5757
return array_merge($configRedirects, $dbRedirects);
5858
}
59+
60+
public function getMorphClass()
61+
{
62+
return 'filament-flexible-content-block-pages::redirect';
63+
}
5964
}

src/Models/Settings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,9 @@ public function defaultSeoImage(): MorphMany
173173
->where('collection_name', static::COLLECTION_DEFAULT_SEO)
174174
->where('custom_properties->locale', app()->getLocale());
175175
}
176+
177+
public function getMorphClass()
178+
{
179+
return 'filament-flexible-content-block-pages::settings';
180+
}
176181
}

src/Models/Tag.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ public function getPreviewUrl(?string $locale = null): string
8181
{
8282
return $this->getPreviewUrl($locale);
8383
}
84+
85+
public function getMorphClass()
86+
{
87+
return 'filament-flexible-content-block-pages::tag';
88+
}
8489
}

src/Models/TagType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,9 @@ public function hasSvgIcon(): bool
105105
{
106106
return $this->icon && Str::contains(trim($this->icon), ['<svg', '<SVG']);
107107
}
108+
109+
public function getMorphClass()
110+
{
111+
return 'filament-flexible-content-block-pages::tag_type';
112+
}
108113
}

src/Resources/PageResource.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public static function form(Form $form): Form
115115
public static function table(Table $table): Table
116116
{
117117
return $table
118-
->mo
119118
->columns([
120119
TitleColumn::create(),
121120
TextColumn::make('created_at')

0 commit comments

Comments
 (0)