dynamic/silverstripe-manageable-dataobject
, (*1)
, (*2)
Allow front-end management of DataObjects., (*3)
Requirements
- SilverStripe ^4.0
- Viewable Dataobject ^2.0
- Additional Form Fields ^2.0
Installation
composer require dynamic/silverstripe-manageable-dataobject
, (*4)
Configuration
MyPageController:
managed_object: MyManageableObject
extensions:
- Dynamic\ManageableDataObject\Extensions\ManageableControllerExtension
MyManageableObject:
extensions:
- Dynamic\ViewableDataObject\Extensions\ViewableDataObject
- Dynamic\ManageableDataObject\Extensions\ManageableObjectExtension
listing_page_class: MyPage
MyManageableObject
To utilize ManageableDataObject you must implement PermissionProvider
and methods defined in ManageableDataObjectInterface
. The example below is a very basic implementation of the PermissionProvider
and ManageableDataObjectInterface
methods., (*5)
<?php
namespace Foo\Bar;
use Dynamic\ManageableDataObject\Interfaces\ManageableDataObjectInterface;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
class MyManageableObject extends DataObject implements PermissionProvider, ManageableDataObjectInterface
{
/**
* @return array
*/
public function providePermissions()
{
return [
'MDO_Create',
'MDO_Edit',
'MDO_Delete',
'MDO_View',
];
}
/**
* @param null $member
* @param array $context
*
* @return bool|int
*/
public function canCreate($member = null, $context = array())
{
return Permission::check('MDO_Create', 'any', $member);
}
/**
* @param null $member
*
* @return bool|int
*/
public function canEdit($member = null)
{
return Permission::check('MDO_Edit', 'any', $member);
}
/**
* @param null $member
*
* @return bool|int
*/
public function canDelete($member = null)
{
return Permission::check('MDO_Delete', 'any', $member);
}
/**
* @param null $member
*
* @return bool|int
*/
public function canView($member = null)
{
return Permission::check('MDO_View', 'any', $member);
}
/**
* @param null $params
*
* @return FieldList
*/
public function getFrontEndFields($params = null)
{
return parent::getFrontEndFields();
}
/**
* @return FieldList
*/
public function getFrontEndActions()
{
return FieldList::create();
}
/**
* @return RequiredFields
*/
public function getFrontEndRequiredFields()
{
return RequiredFields::create();
}
}