From 40ebb9bfa2280dbf4831a99f4ce610b5e49be24e Mon Sep 17 00:00:00 2001 From: flynsarmy Date: Wed, 11 Feb 2015 09:53:21 +1000 Subject: [PATCH 1/2] Support passing custom contexts to relationcontroller --- modules/backend/behaviors/RelationController.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 55fdec738..6319473d3 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -506,7 +506,7 @@ class RelationController extends ControllerBehavior return $results->lists($foreignKeyName); } - + // // Overrides // @@ -1027,10 +1027,12 @@ class RelationController extends ControllerBehavior * Form */ elseif ($this->manageMode == 'form' && isset($this->config->form)) { + $context = !empty($this->config->manage['context']) ? $this->config->manage['context'] : 'relation'; + $config = $this->makeConfig($this->config->form); $config->model = $this->relationModel; $config->arrayName = class_basename($this->relationModel); - $config->context = 'relation'; + $config->context = is_string($context) ? $context : 'relation'; $config->alias = $this->alias . 'ManageForm'; /* @@ -1043,6 +1045,15 @@ class RelationController extends ControllerBehavior 'class' => get_class($config->model), 'id' => $this->manageId ])); } + + if (is_array($context) && isset($context['create'])) { + $config->context = $context['create']; + } + } + else { + if (is_array($context) && isset($context['update'])) { + $config->context = $context['update']; + } } $widget = $this->makeWidget('Backend\Widgets\Form', $config); From 8768ec64d6c9fc76c1d90bd4a58e73c5a165925f Mon Sep 17 00:00:00 2001 From: flynsarmy Date: Wed, 11 Feb 2015 10:17:41 +1000 Subject: [PATCH 2/2] Fix order --- modules/backend/behaviors/RelationController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 6319473d3..f12dd7a63 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -1045,14 +1045,16 @@ class RelationController extends ControllerBehavior 'class' => get_class($config->model), 'id' => $this->manageId ])); } - - if (is_array($context) && isset($context['create'])) { - $config->context = $context['create']; + else { + if (is_array($context) && isset($context['update'])) { + $config->context = $context['update']; + } } + } else { - if (is_array($context) && isset($context['update'])) { - $config->context = $context['update']; + if (is_array($context) && isset($context['create'])) { + $config->context = $context['create']; } }