From 2fc263c31b7e23e2f768dc56f4f0df2912b6b3b1 Mon Sep 17 00:00:00 2001 From: Al Twohill Date: Fri, 8 Mar 2019 14:29:01 +1300 Subject: [PATCH] Fix miss-edited form builder reference --- code/NestedModelController.php | 47 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/code/NestedModelController.php b/code/NestedModelController.php index c342e14..a73f0e9 100644 --- a/code/NestedModelController.php +++ b/code/NestedModelController.php @@ -72,14 +72,22 @@ public function __get($field) { if ($this->hasMethod($funcName = "get$field")) { return $this->$funcName(); - } else if ($this->hasField($field)) { - return $this->getField($field); - } else if ($field == $this->recordType) { - return $this->currentRecord; - } else if ($this->failover) { - return $this->failover->$field; - } else if ($this->parentController) { - return $this->parentController->__get($field); + } else { + if ($this->hasField($field)) { + return $this->getField($field); + } else { + if ($field == $this->recordType) { + return $this->currentRecord; + } else { + if ($this->failover) { + return $this->failover->$field; + } else { + if ($this->parentController) { + return $this->parentController->__get($field); + } + } + } + } } } @@ -87,8 +95,10 @@ public function __call($funcName, $args) { if ($this->hasMethod($funcName)) { return call_user_func_array(array(&$this, $funcName), $args); - } else if ($this->parentController->hasMethod($funcName)) { - return call_user_func_array(array(&$this->parentController, $funcName), $args); + } else { + if ($this->parentController->hasMethod($funcName)) { + return call_user_func_array(array(&$this->parentController, $funcName), $args); + } } } @@ -184,20 +194,26 @@ public function delete($request) function getViewer($action) { if ($this->parentController) { - if (is_numeric($action)) $action = 'view'; + if (is_numeric($action)) { + $action = 'view'; + } $viewer = $this->parentController->getViewer($action); $layoutTemplate = null; // action-specific template with template identifier, e.g. themes/mytheme/templates/Layout/MyModel_view.ss $layoutTemplate = SSViewer::getTemplateFileByType("{$this->recordType}_$action", 'Layout'); // generic template with template identifier, e.g. themes/mytheme/templates/Layout/MyModel.ss - if (!$layoutTemplate) $layoutTemplate = SSViewer::getTemplateFileByType($this->recordType, 'Layout'); + if (!$layoutTemplate) { + $layoutTemplate = SSViewer::getTemplateFileByType($this->recordType, 'Layout'); + } // fallback to controller classname, e.g. iwidb/templates/Layout/NestedModelController.ss $parentClass = static::class; while ($parentClass != Controller::class && !$layoutTemplate) { $layoutTemplate = SSViewer::getTemplateFileByType("{$parentClass}_$action", 'Layout'); - if (!$layoutTemplate) $layoutTemplate = SSViewer::getTemplateFileByType($parentClass, 'Layout'); + if (!$layoutTemplate) { + $layoutTemplate = SSViewer::getTemplateFileByType($parentClass, 'Layout'); + } $parentClass = get_parent_class($parentClass); } @@ -225,7 +241,7 @@ public function Form() } $fields->push(new HiddenField('ID')); - $form = new Form($this, Form::class, $fields, new FieldList(new FormAction('doSave', 'Save')), $required); + $form = new Form($this, __function__, $fields, new FieldList(new FormAction('doSave', 'Save')), $required); if ($this->currentRecord) { $form->loadDataFrom($this->currentRecord); } @@ -290,7 +306,8 @@ public function Breadcrumbs() $parts = explode(self::$breadcrumbs_delimiter, $this->parentController->Breadcrumbs()); // The last part is never a link, need to recreate array_pop($parts); - array_push($parts, '' . $this->parentController->Title . ''); + array_push($parts, + '' . $this->parentController->Title . ''); //Merge array_pop($this->crumbs);