Add a relation to an existing plugin's controller
0
Let's assume the following:
- There is a plugin named "pluginAuthor.pluginName" you want to extend;
- This plugin has a controller named "pluginController";
- You want to add a new relation named "myRelation" to this controller;
- Your plugin is named "myAuthor.myPlugin";
Add the following code to your plugin's boot() method:
pluginController::extend( function ($controller) {
$new_relation = $controller->makeConfigFromArray([
'myrelation' => [
'label' => 'My Relation',
'view' => [
'list' => '$/myauthor/myplugin/models/myrelation/columns.yaml',
'toolbarButtons' => 'add|create|remove',
'showSearch' => true,
],
'manage' => [
'list' => '$/myauthor/myplugin/models/myrelation/columns.yaml',
'form' => '$/myauthor/myplugin/models/myrelation/fields.yaml',
'showSearch' => true,
],
]
]);
$controller->relationConfig = $controller->mergeConfig(
$controller->relationConfig,
$new_relation
);
Alternatively, you can create a config_relation.yaml
file with the new relation(s) and use this code:
pluginController::extend( function ($controller) {
$controller->relationConfig = $controller->mergeConfig(
$controller->relationConfig,
'$/myAuthor/myPlugin/config/config_relation.yaml'
);
});
There are no comments yet
Be the first one to comment