Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

how to prevent certain records from deletion?


Go to End


2 Posts   989 Views

Avatar
woodb2

Community Member, 48 Posts

30 September 2012 at 4:23am

I'm working in ModelAdmin with a couple of DataObjects, Project and Deliverables (Projects have many deliverables). I'm managing the Deliverables from inside Project with a DataObjectManager. Each Deliverables has a hidden field nondelete that if set to yes (1) the user should not be able to delete the record.

I thought that in my Deliveable class I could just set something like:

function canDelete() {
if($this->nondelete == 1) {
return false;
}
}

I'm not sure how to prevent certain records from being deleted. I also tried a few things using OnBeforeDelete() in Deliverables, but had no luck with that either.

Any help would be appreciated,
Brian

Avatar
Willr

Forum Moderator, 5523 Posts

30 September 2012 at 5:54pm

Does that canDelete code not work? I would assume it would, though if you've logged in as an administrator it probably overrides all permission checking. Perhaps structure it so the CMS users are not full admins but another user group which will then check against canDelete().