October CMS resources and help articles

Simple and to the point. Optimized by the community.

Add a relation to an existing plugin's controller

by mjauvin, last modified on February 29th, 2020

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(


1 comment

Post on November 2nd, 2020 5:49 PM

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.
We use cookies to measure the performance of this website. Do you want to accept these cookies?