If we extend the plugin and add the "'Backend.Behaviors.ImportExportController" trait, is not possibile to make it work because relationConfig is not present and there's no way to pass the desired yaml file to use.
I've found that you can implement the RelationController like so:
MyController::extend(function($controller){
$controller->implement[] = 'Backend.Behaviors.RelationController';
});
However, it then throws an error like so:
Class Company\PluginName\Controllers\ControllerName must define property $relationConfig used by Backend\Behaviors\RelationController behavior.
I've tried extending the controller to define the relationConfig file, by adding this inside the extend callback:
$controller->relationConfig = 'path/to/my/relationship.yaml';
However, it doesn't add the property to the controller.
If, however, the controller already has the relationConfig property, doing the above _will_ overwrite it's value. It's as though extending an object only allows you to modify existing properties.
For reference, my full extend callback is like so:
MyController::extend(function($controller){
$controller->relationConfig = 'path/to/my/relationship.yaml';
$controller->implement[] = 'Backend.Behaviors.RelationController';
});
It would be rally handy if this limitation could be resolved. Otherwise it makes it impossible to extend plugin with certain functionality (Namely creating relationships).
This can be overcome by using addDynamicProperty(). See http://octobercms.com/docs/services/behaviors#constructor-extension
Most helpful comment
I've found that you can implement the
RelationControllerlike so:However, it then throws an error like so:
I've tried extending the controller to define the
relationConfigfile, by adding this inside theextendcallback:However, it doesn't add the property to the controller.
If, however, the controller already has the
relationConfigproperty, doing the above _will_ overwrite it's value. It's as though extending an object only allows you to modify existing properties.For reference, my full
extendcallback is like so:It would be rally handy if this limitation could be resolved. Otherwise it makes it impossible to extend plugin with certain functionality (Namely creating relationships).