Skip to content

Instantly share code, notes, and snippets.

@adrexia
Last active March 5, 2020 03:21
Show Gist options
  • Save adrexia/4d47a4c1ebde244c19de413d66eaa201 to your computer and use it in GitHub Desktop.
Save adrexia/4d47a4c1ebde244c19de413d66eaa201 to your computer and use it in GitHub Desktop.
<?php
class MyDataObject extends DataObject implements PermissionProvider {
public function canView($member = NULL, $context = []) {
return Permission::check('MYOBJECT_VIEW');
}
public function canEdit($member = NULL, $context = []) {
return Permission::check('MYOBJECT_EDIT');
}
public function canDelete($member = NULL, $context = []) {
return Permission::check('MYOBJECT_DELETE');
}
public function canCreate($member = NULL, $context = []) {
return Permission::check('MYOBJECT_CREATE');
}
/**
* Get an array of {@link Permission} definitions that this object supports
*
* @return array
*/
public function providePermissions() {
return array(
'MYOBJECT_VIEW' => array(
'name' => 'View My Object',
'category' => 'Module',
),
'MYOBJECT_EDIT' => array(
'name' => 'Edit My Object',
'category' => 'Module',
),
'MYOBJECT_DELETE' => array(
'name' => 'Delete My Object',
'category' => 'Module',
),
'MYOBJECT_CREATE' => array(
'name' => 'Create My Object',
'category' => 'Module'
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment