Add a relation to an existing plugin's controller
2
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:
\Event::listen('system.extendConfigFile', function($publicFile, $config) {
if ($publicFile === '/plugins/pluginauthor/pluginname/controllers/plugincontroller/config_relation.yaml') {
$config['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,
],
];
return $config;
}
});
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'
);
});
Hi, I don't get the example:
what to do if the plugin I want to extend has no config_relation yet (as in trick 1)? how to 'inject' the field into the existing plugin form. Let's say I want to inject a relation to a company into the user plugin.