mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Moved LeftAndMain->doAdd() and AddForm() to subclasses where they're actually used (no possible through a combination of architectural and UI changes)
This commit is contained in:
parent
e6be56e3b4
commit
9e6d70be64
@ -957,63 +957,6 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
function AddForm() {
|
||||
$class = $this->stat('tree_class');
|
||||
|
||||
$typeMap = array($class => singleton($class)->i18n_singular_name());
|
||||
$form = new Form(
|
||||
$this,
|
||||
'AddForm',
|
||||
new FieldList(
|
||||
new HiddenField('ParentID')
|
||||
),
|
||||
new FieldList(
|
||||
FormAction::create('doAdd', _t('AssetAdmin_left.ss.GO','Go'))
|
||||
->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
|
||||
)
|
||||
);
|
||||
$form->addExtraClass('add-form');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new group and return its details suitable for ajax.
|
||||
*/
|
||||
public function doAdd($data, $form) {
|
||||
$class = $this->stat('tree_class');
|
||||
|
||||
// check create permissions
|
||||
if(!singleton($class)->canCreate()) return Security::permissionFailure($this);
|
||||
|
||||
// check addchildren permissions
|
||||
if(
|
||||
singleton($class)->hasDatabaseField('Hierarchy')
|
||||
&& isset($data['ParentID'])
|
||||
&& is_numeric($data['ParentID'])
|
||||
) {
|
||||
$parentRecord = DataObject::get_by_id($class, $data['ParentID']);
|
||||
if(
|
||||
$parentRecord->hasMethod('canAddChildren')
|
||||
&& !$parentRecord->canAddChildren()
|
||||
) return Security::permissionFailure($this);
|
||||
}
|
||||
|
||||
$record = Object::create($class);
|
||||
$form->saveInto($record);
|
||||
$record->write();
|
||||
|
||||
if($this->isAjax()) {
|
||||
$form = $this->getEditForm($record->ID);
|
||||
return $form->forTemplate();
|
||||
} else {
|
||||
return $this->redirect(Controller::join_links($this->Link('show'), $record->ID));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the CMS's HTML-editor toolbar
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user