Prevent users from deleting a single page? #6747
Unanswered
ryanscherler
asked this question in
Q&A
Replies: 1 comment 4 replies
-
You could do this with a custom entry policy. // AppServiceProvider.php
public function boot()
{
$this->app->bind(\Statamic\Policies\EntryPolicy::class, \App\CustomEntryPolicy::class);
} // app/CustomEntryPolicy.php
<?php
namespace App;
use Statamic\Policies\EntryPolicy;
class CustomEntryPolicy extends EntryPolicy
{
public function delete($user, $entry)
{
$undeletable = [
'id-of-home-entry',
// other ids...
];
if (in_array($entry->id(), $undeletable)) {
return false;
}
return parent::delete($user, $entry);
}
} Although super admins will bypass this permission and they'll still be allowed to delete them. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I just first want to say I LOVE Statamic! Thanks so much for this amazing CMS.
One quick question - coming from Craft CMS - there is a concept of a ** 'Single' section type. This allows for the creation of pages that cannot be deleted (e.g. Home page). I am wondering how to do this in Statamic. We have some custom routes that feed an app and pull content from a corresponding page at the moment - but this is fragile, in the event the page is deleted (or slug changed etc.). Is it possible to create a page and set its yaml config to disallow deletion?
Or even just be able to create a 'single' page collection with no delete / create etc?
** Craft reference: https://craftcms.com/docs/4.x/entries.html#singles
Beta Was this translation helpful? Give feedback.
All reactions