This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

KurtJensen
KurtJensen

I need help avoiding an error while extending UsersController from multiple plugins:

In two different plugins Plugin.php files I did :

public function boot()
{
    //...

    UsersController::extend(function($controller) 
    {
        $controller->implement[] = 'Backend.Behaviors.RelationController';

        //...
    }
    //...
}

That causes error:

Class RainLab\User\Controllers\Users has already been extended with Backend\Behaviors\RelationController /home/kurt/www/october/vendor/october/rain/src/Extension/ExtendableTrait.php line 133

So I tried:

public function boot()
{
    //...

    UsersController::extend(function($controller) 
    {
        if (!isset($controller->extensionData['extensions']['Backend.Behaviors.RelationController']))
            $controller->implement[] = 'Backend.Behaviors.RelationController';

        //...
    }
    //...
}

But the if does not result TRUE and therefore this does not work. I have laso tried these variations in my if statement:

isset($controller->extensionData['extensions']['Backend.Behaviors.RelationController'])

isset($controller->extensionData['extensions']['Backend\Behaviors\RelationController'])

is_object($controller->getClassExtension('RelationController'))

is_object($controller->getClassExtension('Backend.Behaviors.RelationController'))

is_object($controller->getClassExtension('Backend\Behaviors\RelationController'))

So what is the proper way to detect if controller has already been extended?

Keios
chris10207
chris10207

this is the way:

RainLabUsersController::extend(function (RainLabUsersController $users) {
            if (!$users->isClassExtendedWith('Backend.Behaviors.RelationController')) {

but you can face a problem with the plugin boot order

Last updated

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.