-
-
Notifications
You must be signed in to change notification settings - Fork 234
Description
Winter CMS Build
1.2.9 and 1.2.11
PHP Version
8.3
Database engine
MySQL/MariaDB
Plugins installed
No response
Issue description
It is not possible to use isClassExtendedWith when extending a controller. This example from the documentation https://wintercms.com/docs/v1.2/docs/services/behaviors#extending-a-clas generates an Exception if the controller is already extended using the same behavior:
UsersController::extend(function ($controller) {
// Implement behavior if not already implemented
if (!$controller->isClassExtendedWith(\Backend\Behaviors\RelationController::class)) {
$controller->implement[] = \Backend\Behaviors\RelationController::class;
}
// Define property if not already defined
if (!isset($controller->relationConfig)) {
$controller->addDynamicProperty('relationConfig');
}
// Splice in configuration safely
$myConfigPath = '$/myvendor/myplugin/controllers/users/config_relation.yaml';
$controller->relationConfig = $controller->mergeConfig(
$controller->relationConfig,
$myConfigPath
);
}Exception
Class Backend\Controllers\Users has already been extended with Backend\Behaviors\RelationController
With ExtendableTrait::extendableConstruct() the order seems to be:
- First: all
extend()callbacks are run (including yours). - Then: the behaviors listed in
$implementare applied (including RelationController).
And isClassExtendedWith() returns true only when the behavior has already been applied (i.e. when it is present in extensionData['extensions']).
Steps to replicate
When UsersController already implement \Backend\Behaviors\RelationController::class, try this in boot() on your Plugin.php:
UsersController::extend(function ($controller) {
// Implement behavior if not already implemented
if (!$controller->isClassExtendedWith(\Backend\Behaviors\RelationController::class)) {
$controller->implement[] = \Backend\Behaviors\RelationController::class;
}
}You can try with other controllers and other behaviors, like \Backend\Behaviors\FormController::class or \Backend\Behaviors\ListController::class for example. Same issue.
Workaround
No response