Skip to content

Commit

Permalink
Fix miss-edited form builder reference
Browse files Browse the repository at this point in the history
  • Loading branch information
altwohill committed Mar 8, 2019
1 parent 2e4f696 commit 2fc263c
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions code/NestedModelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,33 @@ 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);
}
}
}
}
}
}

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);
}
}
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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, '<a href="' . $this->parentController->Link() . '">' . $this->parentController->Title . '</a>');
array_push($parts,
'<a href="' . $this->parentController->Link() . '">' . $this->parentController->Title . '</a>');

//Merge
array_pop($this->crumbs);
Expand Down

0 comments on commit 2fc263c

Please sign in to comment.