-1

As an example I have a translatable model:

class Settings extends Model {
    public $implement = [
        'System.Behaviors.SettingsModel',
        'RainLab.Translate.Behaviors.TranslatableModel'
    ];

    public $settingsCode = 'zollerboy_customtheme_settings';
    public $settingsFields = 'fields.yaml';

    public $translatable = [
        'site_name',
        //I have a lot more here
    ];
}

My fields.yaml looks like this:

tabs:
    fields:
        site_name:
            tab: Info
            label: Website Name
            type: text

        # And so on ...

Is it possible, that I give the field site_name a default value for each language?

I tried it with

default: name.plugin::lang.settings.default.site_name

but that seems to just work with labels but not with default values.

Josef Zoller
  • 921
  • 2
  • 8
  • 24

1 Answers1

0

Yes, the default option does not work with translations, but you can display this field through of the widget form, getting the default value in the visualization method.

public function render() {
    $value= Lang::get('name.plugin::lang.settings.default.site_name');
    return $this->makePartial('site_name', ['value' => $value, 'name' => 
    'site_name']);
}

Register form widgets by overriding the registerFormWidgets method inside the Plugin registration class.

public function registerFormWidgets() {
    return [
          'Name\Plugin\FormWidgets\SiteName' => 'site_name'

    ];
}

Example fields.yaml:

tabs:
fields:
    site_name:
        tab: Info
        label: Website Name
        type: site_name

    # And so on ...
Alleks
  • 11
  • 2
  • But this does override the values, that are different then the default value, right? – Josef Zoller Nov 11 '18 at 13:53
  • This field output is similar to your example above only through your widget. Here $value is the default – Alleks Nov 11 '18 at 14:35
  • In the visualization method can add a condition to not override the default value. – Alleks Nov 11 '18 at 15:04
  • Everything works for me, maybe we are talking about different things. I uploaded a test plugin on github.com - https://github.com/Alleksk/test-plugin – Alleks Nov 13 '18 at 16:01