Settings
This lets you create a settings page in the admin area and also provides a facade for accessing those settings.
Extra Settings
Create a file to encapsulate your group of settings. For an example see Yadda\Enso\Settings\Crud\ExtraFields\SocialAccounts which is installed by default.
Here is a simple example that adds a new a divider on the "main" tab and adds a text field below that.
use Yadda\Enso\Crud\Forms\Fields\DividerField;
use Yadda\Enso\Crud\Forms\Fields\TextField;
use Yadda\Enso\Crud\Forms\Form;
use Yadda\Enso\Settings\Contracts\ExtraSettings;
class CopyrightText implements ExtraSettings
{
/**
* Take a form and process it by adding, removing
* or updating sections or fields.
*
* @param Form $form
*
* @return Form
*/
public static function updateForm(Form $form): Form
{
$form
->getSection('main')
->addFields([
DividerField::make('copyright')
->setTitle('Copyright'),
TextField::make('copyright'),
]);
return $form;
}
}
You are free to manipulate the form here in any way that you would in the create or edit methods of your CRUD config.
Finally, enable this file by adding it to the config.
// config/enso/settings.php
'extra' => [
// ...
App\Enso\Crud\ExtraSettings\Copyright::class,
],
Adding Settings Manually
If you don't want to use the Extra Settings method described above (though you probably should), you can manage settings as you would any other crud. For example:
class Setting extends BaseCrud
{
public function create(Form $form) {
$form = parent::create($form);
$form
->getSectionByName('main')
->setLabel('Global')
->addField([
(new TextField('some_setting'))
]);
$form->addSections([
(new CollectionSection('social'))
->addFields([
(new TextField('twitter_url')),
(new TextField('instagram_url')),
(new TextField('phone')),
(new TextField('email')),
]);
]);
return $form;
}
}
Accessing Settings
EnsoSettings::get('some_setting', 'Fallback for if some_setting does not exist.');
Creating/Updating Settings
This needs some work. You need to do something like this:
EnsoSettings::set('some_setting', 'Here is a setting', [
'type' => 'scalar',
'content' => [
'id' => 'some_setting',
],
]);
Except that that doesn't set the ID correctly. So you'll need to do something like this:
/**
* Temporary feature to set settings as the Current implementation
* doesn't key new items properly.
*
* @param string $name
* @param mixed $value
* @param array $data_type - Get from instance of Field
*
* @return void
*/
protected function setSetting($name, $value, $data_type)
{
$this->app->make('ensosettings')->set($name, $value, $data_type);
$this->app->make('ensosettings')->all()->put($name, $this->app->make('ensosettings')->getSetting(0));
$this->app->make('ensosettings')->all()->forget(0);
}
Installation
Settings should be set up by default when you install Enso. If that's not the case, maybe you need to do some opf these things manually.
Add the ServiceProvider to config/app.php.
Yadda\Enso\EnsoSettingsServiceProvider::class,
Add an alias to the Settings Facade.
'EnsoSettings' => Yadda\Enso\Settings\Facades\EnsoSettings::class,
Publish the CRUD.
php artisan vendor:publish
Run the migration to create the enso_settings table.
php artisan migrate