mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
ENHANCEMENT Supporting passing in objects in LeftAndMain->getRecord() (and subclasses) in order to reduce boilerplate code in controller actions
This commit is contained in:
parent
934c3f2c1b
commit
824f7451a0
@ -369,7 +369,9 @@ JS;
|
|||||||
public function getRecord($id) {
|
public function getRecord($id) {
|
||||||
$treeClass = $this->stat('tree_class');
|
$treeClass = $this->stat('tree_class');
|
||||||
|
|
||||||
if($id && is_numeric($id)) {
|
if($id instanceof $treeClass) {
|
||||||
|
return $id;
|
||||||
|
} else if($id && is_numeric($id)) {
|
||||||
$version = isset($_REQUEST['Version']) ? $_REQUEST['Version'] : null;
|
$version = isset($_REQUEST['Version']) ? $_REQUEST['Version'] : null;
|
||||||
if(is_numeric($version)) {
|
if(is_numeric($version)) {
|
||||||
$record = Versioned::get_version($treeClass, $id, $version);
|
$record = Versioned::get_version($treeClass, $id, $version);
|
||||||
@ -417,11 +419,12 @@ JS;
|
|||||||
// Include JavaScript to ensure HtmlEditorField works.
|
// Include JavaScript to ensure HtmlEditorField works.
|
||||||
HtmlEditorField::include_js();
|
HtmlEditorField::include_js();
|
||||||
|
|
||||||
|
if(!$id) $id = $this->currentPageID();
|
||||||
$form = parent::getEditForm($id);
|
$form = parent::getEditForm($id);
|
||||||
|
|
||||||
// TODO Duplicate record fetching (see parent implementation)
|
// TODO Duplicate record fetching (see parent implementation)
|
||||||
if(!$id) $id = $this->currentPageID();
|
$record = $this->getRecord($id);
|
||||||
$record = ($id && $id != "root") ? $this->getRecord($id) : null;
|
if($record && !$record->canView()) return Security::permissionFailure($this);
|
||||||
|
|
||||||
$fields = $form->Fields();
|
$fields = $form->Fields();
|
||||||
$actions = $form->Actions();
|
$actions = $form->Actions();
|
||||||
|
@ -474,10 +474,14 @@ class LeftAndMain extends Controller {
|
|||||||
return $this->renderWith($this->getTemplatesWithSuffix('_right'));
|
return $this->renderWith($this->getTemplatesWithSuffix('_right'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRecord($id, $className = null) {
|
public function getRecord($id) {
|
||||||
if($id && is_numeric($id)) {
|
$className = $this->stat('tree_class');
|
||||||
if(!$className) $className = $this->stat('tree_class');
|
if($id instanceof $className) {
|
||||||
|
return $id;
|
||||||
|
} else if(is_numeric($id)) {
|
||||||
return DataObject::get_by_id($className, $id);
|
return DataObject::get_by_id($className, $id);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -743,9 +747,13 @@ class LeftAndMain extends Controller {
|
|||||||
|
|
||||||
public function getEditForm($id = null) {
|
public function getEditForm($id = null) {
|
||||||
if(!$id) $id = $this->currentPageID();
|
if(!$id) $id = $this->currentPageID();
|
||||||
|
|
||||||
$record = ($id && $id != "root") ? $this->getRecord($id) : null;
|
if(is_object($id)) {
|
||||||
if($record && !$record->canView()) return Security::permissionFailure($this);
|
$record = $id;
|
||||||
|
} else {
|
||||||
|
$record = ($id && $id != "root") ? $this->getRecord($id) : null;
|
||||||
|
if($record && !$record->canView()) return Security::permissionFailure($this);
|
||||||
|
}
|
||||||
|
|
||||||
if($record) {
|
if($record) {
|
||||||
$fields = $record->getCMSFields();
|
$fields = $record->getCMSFields();
|
||||||
|
@ -42,8 +42,13 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getEditForm($id = null) {
|
function getEditForm($id = null) {
|
||||||
|
// TODO Duplicate record fetching (see parent implementation)
|
||||||
if(!$id) $id = $this->currentPageID();
|
if(!$id) $id = $this->currentPageID();
|
||||||
$record = ($id && $id != "root") ? $this->getRecord($id) : null;
|
$form = parent::getEditForm($id);
|
||||||
|
|
||||||
|
// TODO Duplicate record fetching (see parent implementation)
|
||||||
|
$record = $this->getRecord($id);
|
||||||
|
if($record && !$record->canView()) return Security::permissionFailure($this);
|
||||||
|
|
||||||
if($id && is_numeric($id)) {
|
if($id && is_numeric($id)) {
|
||||||
$form = parent::getEditForm($id);
|
$form = parent::getEditForm($id);
|
||||||
|
Loading…
Reference in New Issue
Block a user