From 05be648749ef004d834813826b2e66a45703303a Mon Sep 17 00:00:00 2001 From: Patryk Date: Tue, 7 Sep 2021 21:03:10 +0200 Subject: [PATCH] fix relation controller --- eventhandlers/RainlabUserHandler.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/eventhandlers/RainlabUserHandler.php b/eventhandlers/RainlabUserHandler.php index 658af76..b06615c 100644 --- a/eventhandlers/RainlabUserHandler.php +++ b/eventhandlers/RainlabUserHandler.php @@ -46,6 +46,26 @@ public function addClusterRelation($event) public function addClusterField($event) { + /** + * Extend the RainLab.Users controller to include the RelationController behavior too + */ + Users::extend(function ($controller) { + + // Implement the list controller behavior dynamically + if (!$controller->isClassExtendedWith('Backend.Behaviors.RelationController')) { + $controller->implement[] = 'Backend.Behaviors.RelationController'; + } + + // Declare the relationConfig property dynamically for the RelationController behavior to use + if (!isset($controller->relationConfig)) { + $controller->addDynamicProperty('relationConfig'); + } + + $relationConfigPath = '$/initbiz/cumuluscore/controllers/users/config_relation.yaml'; + + $controller->relationConfig = $controller->mergeConfig($controller->relationConfig, $relationConfigPath); + }); + Users::extendFormFields(function ($widget) { // Prevent extending of related form instead of the intended User form if (!$widget->model instanceof User) { @@ -54,8 +74,9 @@ public function addClusterField($event) $config = []; $config['clusters'] = [ - 'tab' => 'initbiz.cumuluscore::lang.users.cluster_tab', - 'type' => 'partial', + 'tab' => 'initbiz.cumuluscore::lang.users.cluster_tab', + 'type' => 'partial', + 'path' => '$/initbiz/cumuluscore/controllers/users/_clusters.htm' ]; $widget->addTabFields($config);