From 0c4c39fddb99ed18d4d0990d15004417cf6058f5 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 1 Feb 2016 14:53:53 +1000 Subject: [PATCH] Add morphic relations to backend --- modules/backend/behaviors/RelationController.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index e9431dbe7..29e80d8ff 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -1102,7 +1102,7 @@ class RelationController extends ControllerBehavior if ($this->relationType == 'belongsToMany') { $this->relationObject->detach($checkedIds); } - elseif ($this->relationType == 'hasMany') { + elseif ($this->relationType == 'hasMany' || $this->relationType == 'morphMany') { $relatedModel = $this->relationObject->getRelated(); foreach ($checkedIds as $relationId) { if ($obj = $relatedModel->find($relationId)) { @@ -1121,7 +1121,7 @@ class RelationController extends ControllerBehavior $this->relationObject->dissociate(); $this->relationObject->getParent()->save(); } - elseif ($this->relationType == 'hasOne') { + elseif ($this->relationType == 'hasOne' || $this->relationType == 'morphOne') { if ($obj = $this->relationModel->find($recordId)) { $this->relationObject->remove($obj); } @@ -1295,10 +1295,12 @@ class RelationController extends ControllerBehavior switch ($this->relationType) { case 'hasMany': + case 'morphMany': case 'belongsToMany': return ['create', 'add', 'delete', 'remove']; case 'hasOne': + case 'morphOne': case 'belongsTo': return ['create', 'update', 'link', 'delete', 'unlink']; } @@ -1316,10 +1318,12 @@ class RelationController extends ControllerBehavior switch ($this->relationType) { case 'hasMany': + case 'morphMany': case 'belongsToMany': return 'multi'; case 'hasOne': + case 'morphOne': case 'belongsTo': return 'single'; } @@ -1358,7 +1362,9 @@ class RelationController extends ControllerBehavior else return 'list'; case 'hasOne': + case 'morphOne': case 'hasMany': + case 'morphMany': if ($this->eventTarget == 'button-add') return 'list'; else return 'form'; }