Skip to content

Commit

Permalink
NEW Don't modify the field if no canCreate
Browse files Browse the repository at this point in the history
This stops the Add button showing if the member doesn't have permission to create the object type.
  • Loading branch information
dhensby committed Feb 9, 2015
1 parent a999c11 commit 943340c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions code/extensions/QuickAddNewExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public function useAddNew($class, $sourceCallback, FieldList $fields = null, Req
if(!is_callable($sourceCallback)){
throw new Exception('the useAddNew method must be passed a callable $sourceCallback parameter, ' . gettype($sourceCallback) . ' passed.');
}

// if the user can't create this object type, don't modify the form
if (!singleton($class)->canCreate()) {
return $this->owner;
}

Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
Expand Down Expand Up @@ -132,6 +137,9 @@ public function AddNewFormHTML(){
**/
public function doAddNew($data, $form){
$obj = Object::create($this->addNewClass);
if (!$obj->canCreate()) {
return Security::permissionFailure(Controller::curr(), "You don't have permission to create this object");
}
$form->saveInto($obj);

try {
Expand Down

0 comments on commit 943340c

Please sign in to comment.