I create a little plugin for the OctoberCMS but now dealing with a problem of setting a default value for a settings form.
I used database storage for my plugin settings (Backend -> Settings tab -> My Plugin tab) which works , quite good, except I caot set default values.
I have a fields.yaml with this content:
tabs:
fields:
reviews_border_color:
label: 'Field1'
span: left
tab: 'review_sticker'
required: 1
type: text
default: '#F2F2F2'
rating_star_size:
label: 'Field2'
span: left
tab: 'review_sticker'
required: 1
type: number
default: 14
I retrieve the settings in my components like this:
<?php namespace CodedgeTestPluginComponents;
use CmsClassesComponentBase;
use CodedgeTestPluginModelsSettings;
class TestComponent extends ComponentBase
{
public $starSize;
public $borderColor;
public function componentDetails()
{
retu [
'name' => 'Test Component',
'description' => '...'
];
}
public function defineProperties()
{
retu [];
}
public function init()
{
$this->starSize = Settings::get('rating_star_size'); // not giving a default value when empty, default is 14
$this->borderColor = Settings::get('reviews_border_color'); // not giving a default value when empty, default is '#F2F2F2'
}
}
I also tried to set the default value as second param in the get() method, like this:
public function init()
{
$this->starSize = Settings::get('rating_star_size', 14); // retus null
$this->borderColor = Settings::get('reviews_border_color', '#F2F2F2'); // retus null
}
So any suggestions how I can reliably set a default value if none is specified/entered in to the settings form field?
