$record = MyDataObject::get()->byID($id); if ($record && $record->canEdit()) { // allow the user to edit the record } else { // deny access to edit the record }
$group = Group::get()->byID($groupID); if ($group && $group->canEdit(MyDataObject::class)) { // allow the group to edit records of the MyDataObject class } else { // deny access to edit records of the MyDataObject class }This example fetches a specific group from the database and checks whether it has permission to edit records of the "MyDataObject" class. If the group has permission, some editing functionality can be enabled. If not, the editing functionality is disabled. The DataObject canEdit method is part of the SilverStripe ORM library, which is included in the SilverStripe CMS package.