I created a form for a block plugin. I'm attempting to save the values to the form after submitting. However I'm having trouble saving the values if they are within an array.
For instance
public function blockForm($form, FormStateInterface $form_state){
$form['plugins_string_text'] = array(
'#type' => 'text_format',
'#title' => $this->t('Block contents'),
'#format' => 'full_html',
'#description' => $this->t('This text will appear in the block.'),
'#default_value' => $this->configuration['plugins_string_text-submit'],
);
$form['header']['margin-top'] = array(
'#type' => 'textfield',
'#title' => t('Margin Top (pixels)'),
'#default_value' => $this->configuration['header']['margin-top-submit'],
);
$form['header']['margin-bottom'] = array(
'#type' => 'textfield',
'#title' => t('Margin Bottom (pixels)'),
'#default_value' => $this->configuration['header']['margin-bottom-submit'],
);
$form['header']['margin-left'] = array(
'#type' => 'textfield',
'#title' => t('Margin Left (pixels)'),
'#default_value' => $this->configuration['header']['margin-left-submit'],
);
$form['header']['margin-right'] = array(
'#type' => 'textfield',
'#title' => t('Margin Right (pixels)'),
'#default_value' => $this->configuration['header']['margin-right-submit'],
);
}
public function blockSubmit($form, FormStateInterface $form_state) {
$this->configuration['plugins_string_text-submit'] = $form_state->getValue('plugins_string_text');
$this->configuration['header']['margin-top-submit'] = $form_state->getValue('header','margin-top');
$this->configuration['header']['margin-bottom-submit'] = $form_state->getValue('header','margin-bottom');
$this->configuration['header']['margin-right-submit'] = $form_state->getValue('header','margin-right');
$this->configuration['header']['margin-left-submit'] = $form_state->getValue('header','margin-left');
}
This is saved to the form properly
$this->configuration['plugins_string_text-submit'] = $form_state->getValue('plugins_string_text');
However each of the lines below display the entirety of the 'header' array instead of the individual margin values.
$this->configuration['header']['margin-top-submit'] = $form_state->getValue('header','margin-top');
$this->configuration['header']['margin-bottom-submit'] = $form_state->getValue('header','margin-bottom');
$this->configuration['header']['margin-right-submit'] = $form_state->getValue('header','margin-right');
$this->configuration['header']['margin-left-submit'] = $form_state->getValue('header','margin-left');
What is the proper way to use getValue to reach an element within an array. Or is there another function I should be using?