Skip to content
Snippets Groups Projects
Commit bf735fba authored by Shibin Das's avatar Shibin Das
Browse files

Issue #3461595: Refactor to use #config_target

parent 47ab2875
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ rift.settings:
config:
type: mapping
label: 'Config'
additionalProperties: false
mapping:
screens:
type: sequence
......@@ -22,11 +23,10 @@ rift.settings:
nullable: false
type: string
label: 'Media Query'
transforms:
type: string
label: 'Transforms'
multiplier:
multipliers:
type: sequence
label: 'List of Multiplier'
sequence:
......@@ -54,22 +54,26 @@ rift.settings:
type: string
label: 'Url Generation Strategy'
view_modes:
type: mapping
type: sequence
label: 'View Modes'
mapping:
label:
type: string
label: 'Label'
sizes:
type: string
label: 'Sizes'
aspect_ratios:
type: string
label: 'Aspect Ratios'
attributes:
type: map
label: 'Attributes'
sequence:
type: mapping
label: 'View Mode'
mapping:
label:
type: string
label: 'Label'
sizes:
type: string
label: 'Sizes'
aspect_ratios:
type: string
label: 'Aspect Ratios'
attributes:
type: map
label: 'Attributes'
required: ["sizes"]
additionalProperties: false
field.formatter.settings.rift_picture:
type: mapping
......
......@@ -3,6 +3,7 @@
namespace Drupal\rift\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\ConfigTarget;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\Yaml\Yaml;
......@@ -34,12 +35,28 @@ class RiftSettingsForm extends ConfigFormBase {
'#title' => $this->t('Default Config'),
'#attributes' => ['data-yaml-editor' => 'true'],
'#default_value' => Yaml::dump($this->config('rift.settings')->get('config')),
'#config_target' => new ConfigTarget(
'rift.settings',
'config',
// Converts config value to a form value.
fn($value) => Yaml::dump($value),
// Converts form value to a config value.
fn($value) => Yaml::parse($value),
),
];
$form['view_modes'] = [
'#type' => 'textarea',
'#title' => $this->t('View Modes'),
'#attributes' => ['data-yaml-editor' => 'true'],
'#default_value' => Yaml::dump($this->config('rift.settings')->get('view_modes')),
'#config_target' => new ConfigTarget(
'rift.settings',
'view_modes',
// Converts config value to a form value.
fn($value) => Yaml::dump($value),
// Converts form value to a config value.
fn($value) => Yaml::parse($value),
),
];
return parent::buildForm($form, $form_state);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment