Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relation controller #43

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions eventhandlers/RainlabUserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down