Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 60fba44

Browse files
author
Matthew Hailwood
committed
Allow fallback to standard Page class if static::$relationOwner` is null
1 parent 0390642 commit 60fba44

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ would result in something like "1 |18 |19 |24".
4242
##OwnerPermissionedDataObject##
4343
- Allows data objects to inherit the access permissions from their attached relation parent
4444
- Relation parent defaults to `Page()`
45+
- If `static::$relationOwner` is set to `null` will fall back to asking the standard `Page` for permission
4546

4647
#Page Types Overview#
4748

code/OwnerPermissionedDataObject.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class OwnerPermissionedDataObject extends DataObject {
1414
* @return DataObject
1515
*/
1616
protected function RelationOwner() {
17-
if ($this->hasMethod(static::$relationOwnerMethod)) {
17+
if (is_null(static::$relationOwnerMethod)) {
18+
return false;
19+
} elseif ($this->hasMethod(static::$relationOwnerMethod)) {
1820
return $this->{static::$relationOwnerMethod}();
1921
} else {
2022
throw new BadMethodCallException(
@@ -24,18 +26,22 @@ protected function RelationOwner() {
2426
}
2527

2628
public function canView($member = null) {
27-
return $this->RelationOwner()->canView($member);
29+
return $this->askOwnerForPermission(__FUNCTION__, $member);
2830
}
2931

3032
public function canEdit($member = null) {
31-
return $this->RelationOwner()->canEdit($member);
33+
return $this->askOwnerForPermission(__FUNCTION__, $member);
3234
}
3335

3436
public function canDelete($member = null) {
35-
return $this->RelationOwner()->canDelete($member);
37+
return $this->askOwnerForPermission(__FUNCTION__, $member);
3638
}
3739

3840
public function canCreate($member = null) {
39-
return $this->RelationOwner()->canCreate($member);
41+
return $this->askOwnerForPermission(__FUNCTION__, $member);
42+
}
43+
44+
protected function askOwnerForPermission($method, $member){
45+
return $this->RelationOwner() ? $this->RelationOwner()->{$method}($member) : singleton('Page')->{$method}($member);
4046
}
4147
}

0 commit comments

Comments
 (0)