Skip to content

Commit

Permalink
#15 Updated README.
Browse files Browse the repository at this point in the history
  • Loading branch information
conny-nyman committed Dec 6, 2019
1 parent 03403ba commit a7c95f2
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,58 @@ Keep your Silverstripe CMS 4 code DRY!
## Test/Validation utils
- Generate error message strings

## Example usage
## Data object permission extension

Apply and configure:

- `canView`
- `canEdit`
- `canCreate`
- `canDelete`

permission checks to data objects through an extension.

## Example usages

### Apply permission checks to data objects

First set the allowed group codes in a config file.

```
Conan\DataObjectUtils\DataObjectGroupPermissionExtension:
can_view_group_codes:
- 'administrators'
- 'can_view_group_codes'
can_edit_group_codes:
- 'administrators'
- 'can_edit_group_codes'
can_create_group_codes:
- 'administrators'
- 'can_create_group_codes'
can_delete_group_codes:
- 'administrators'
- 'can_delete_group_codes'
```

Then apply the extension to data objects.

```
namespace The\Namespace;
use Conan\DataObjectUtils\DataObjectGroupPermissionExtension;
use SilverStripe\ORM\DataObject;
class MyClass extends DataObject
{
private static $extensions = [
DataObjectGroupPermissionExtension::class,
];
}
```

### Translate CMS fields

```
namespace The\Namespace;
use Conan\DataObjectUtils\DBConstants;
Expand Down Expand Up @@ -58,6 +107,7 @@ en:

By default the namespaced class name is used, but it is possible to pass a custom value as the caller class.
e.g. `CMSFieldUtils::setTitle($myStringField, 'My title', 'MyModule');` and then translate it like this:

```
en:
MyModule:
Expand Down

0 comments on commit a7c95f2

Please sign in to comment.