This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi, How to extend plugin using sluggable trait?
Where I should put use \October\Rain\Database\Trait\Sluggable
in my plugin?
I need to extend MyCalendar plugin by KurtJensen.
Thanks
This trait is only for models. You use trait inside model class.
Next you specify what columns in database are slugs and this trait will do the rest.
In documentation you have an example how to use this: http://octobercms.com/docs/database/traits#sluggable
You can try to implement trait in your plugin boot method:
CalendarModel::extend(function($model) {
$model->implement[] = 'October.Rain.Database.Trait.Sluggable';
});
But I don't know if this implement array can be used with traits or only with behaviors.
Another option is to create in your plugin new model class and extend CalendarModel class. You will have to override formConfig and listConfig to use your model instead of plugin original.
The simplest solution is to write an issue on plugin page, meybe what you have to do can be implemented inside original plugin and author can integrate that for you.
I have the same problem. How should traits be added to an existing model while extending plugins?
I tried the following:
UserModel::extend(function($model) {
$model->implement[] = 'October.Rain.Database.Trait.Nullable';
$model->nullable[] = 'company';
});
And got this error:
Indirect modification of overloaded property RainLab\User\Models\User::$nullable has no effect
Last updated
For anyone encountered this issue, you can use Behaviors
when attaching purgeable attribute to the extended model
BlogModel::extend(function($model){ $model->implement[] = 'October.Rain.Database.Behaviors.Purgeable'; $model->addDynamicProperty('purgeable', ['post_publish']); });
Last updated
1-6 of 6