Skip to content

Commit 71edb66

Browse files
committed
Add page observer to really block deletion of page used in menu item
1 parent 70967c1 commit 71edb66

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,8 @@ check:
403403
- Seppe: menu components ok?
404404

405405
menu:
406-
- page delete modal when page used in menu
407-
- orm listeners for linkable models that are in a menu to avoid accidental deletion.
408406
- caching tree model + observer to clear cache
409-
- Menu titels
407+
- Menu titels menu items
410408
- Ben: add menu to default page template
411409
- test global search and improve table search and ordering
412410

src/Models/Page.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Statikbe\FilamentFlexibleContentBlockPages\Models;
44

5+
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
56
use Illuminate\Database\Eloquent\Factories\HasFactory;
67
use Illuminate\Database\Eloquent\Model;
78
use Spatie\MediaLibrary\HasMedia;
89
use Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages;
910
use Statikbe\FilamentFlexibleContentBlockPages\Models\Concerns\HasTitleMenuLabelTrait;
1011
use Statikbe\FilamentFlexibleContentBlockPages\Models\Contracts\HasMenuLabel;
12+
use Statikbe\FilamentFlexibleContentBlockPages\Observers\PageObserver;
1113
use Statikbe\FilamentFlexibleContentBlocks\Models\Concerns\HasAuthorAttributeTrait;
1214
use Statikbe\FilamentFlexibleContentBlocks\Models\Concerns\HasCodeTrait;
1315
use Statikbe\FilamentFlexibleContentBlocks\Models\Concerns\HasDefaultContentBlocksTrait;
@@ -34,6 +36,7 @@
3436
/**
3537
* @property bool $is_undeletable
3638
*/
39+
#[ObservedBy(PageObserver::class)]
3740
class Page extends Model implements HasCode, HasContentBlocks, HasHeroCallToActionsAttribute, HasHeroImageAttributes, HasIntroAttribute, HasMedia, HasMediaAttributes, HasMenuLabel, HasOverviewAttributes, HasPageAttributes, HasParent, HasSEOAttributes
3841
{
3942
use HasAuthorAttributeTrait;

src/Observers/PageObserver.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Statikbe\FilamentFlexibleContentBlockPages\Observers;
4+
5+
use Statikbe\FilamentFlexibleContentBlockPages\Models\Page;
6+
7+
class PageObserver
8+
{
9+
/**
10+
* Checks if the page is used in a menu item and blocks deletion.
11+
*/
12+
public function deleting(Page $page): bool
13+
{
14+
if ($page->menuItem) {
15+
return false;
16+
}
17+
18+
return true;
19+
}
20+
}

0 commit comments

Comments
 (0)