2

How can we extend a plugin by adding Backend.Behaviors.RelationController to one of its controllers? I need to extend the User Plugin and add a belongsToMany relationship to its User model. I also want to extend its Users controller to implement the Backend.Behaviors.RelationController behavior. I know that form fields can be extended using extendFormFields and list columns can be extended using extendListColumns. But what about extending a plugin by adding or editing the RelationController behavior?

B Faley
  • 17,120
  • 43
  • 133
  • 223

1 Answers1

2

Read up on the Behavior documentation, specifically as it relates to extending classes to implement new behaviors.

Essentially, you will need to extend the Users controller to both implement the RelationController behavior and configure that behavior. A code example accomplishing that is below:

UsersController::extend(function($controller) {
    $controller->implement[] = ['Backend.Behaviors.RelationController'];
    $controller->relationConfig = '$/myvendor/myplugin/controllers/users/config_relation.yaml'
});
LukeTowers
  • 1,262
  • 7
  • 14