mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
updated canCreate function to check for Parent object
This commit is contained in:
parent
d8a8ddc61d
commit
b49d38ff0f
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace SilverStripe\UserForms\Model\EditableFormField;
|
namespace SilverStripe\UserForms\Model\EditableFormField;
|
||||||
|
|
||||||
use SilverStripe\Control\Controller;
|
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\Security\Member;
|
use SilverStripe\Security\Member;
|
||||||
@ -134,11 +133,12 @@ class EditableOption extends DataObject
|
|||||||
*/
|
*/
|
||||||
public function canCreate($member = null, $context = [])
|
public function canCreate($member = null, $context = [])
|
||||||
{
|
{
|
||||||
// Check parent page
|
// Check parent object
|
||||||
$parent = $this->getCanCreateContext(func_get_args());
|
$parent = $this->Parent();
|
||||||
if ($parent) {
|
if ($parent) {
|
||||||
return $parent->canEdit($member);
|
return $parent->canCreate($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to secure admin permissions
|
// Fall back to secure admin permissions
|
||||||
return parent::canCreate($member);
|
return parent::canCreate($member);
|
||||||
}
|
}
|
||||||
@ -159,24 +159,4 @@ class EditableOption extends DataObject
|
|||||||
{
|
{
|
||||||
return $this->canDelete($member);
|
return $this->canDelete($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to check the parent for this object
|
|
||||||
*
|
|
||||||
* @param array $args List of arguments passed to canCreate
|
|
||||||
* @return DataObject Some parent dataobject to inherit permissions from
|
|
||||||
*/
|
|
||||||
protected function getCanCreateContext($args)
|
|
||||||
{
|
|
||||||
// Inspect second parameter to canCreate for a 'Parent' context
|
|
||||||
if (isset($args[1]['Parent'])) {
|
|
||||||
return $args[1]['Parent'];
|
|
||||||
}
|
|
||||||
// Hack in currently edited page if context is missing
|
|
||||||
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
|
||||||
return Controller::curr()->currentPage();
|
|
||||||
}
|
|
||||||
// No page being edited
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user