October CMS resources and help articles

Simple and to the point. Optimized by the community.

How to translate fields added dynamically to a Model (or CMS Page)

0
by mjauvin, last modified on March 12th, 2020

Since the RainLab.Translate plugin uses the backend.form.extendFieldsBefore event to replace regular form fields with their multi-lang equivalent, new fields must be added using this event as well, otherwise they won't be translatable.

In your plugin's boot() method, create the new field and add it to the model's translatable property array:

Event::listen('backend.form.extendFieldsBefore', function($widget) {
   $widget->tabs['fields']['myField'] = [
      'label' => 'My New Field',
      'type' => text,
      'tab' => 'myTab'
   ];
});

YourModel::extend(function($model) {
   $model->translatable = array_merge($model->translatable, ['myField']);
});

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?