Blog-plugin: Add relationConfig definition in Posts controller

Created on 4 Oct 2015  路  3Comments  路  Source: rainlab/blog-plugin

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.

Unconfirmed Bug

Most helpful comment

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).

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drmzio picture drmzio  路  8Comments

mateoprifti picture mateoprifti  路  3Comments

karnold picture karnold  路  5Comments

daveharrisonnet picture daveharrisonnet  路  9Comments

Calinou picture Calinou  路  4Comments