public function DashboardSettingsForm::submitForm in Content Planner 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ConfigFormBase::submitForm
File
- src/
Form/ DashboardSettingsForm.php, line 132
Class
- DashboardSettingsForm
- Defines a form that configures forms module settings.
Namespace
Drupal\content_planner\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$block_configurations = $this->dashboardSettingsService
->getBlockConfigurations();
// Get values.
$values = $form_state
->getValues();
foreach ($values['enabled_blocks'] as $key => $selected) {
if ($selected) {
// If the block is not in the config already.
if (!array_key_exists($key, $block_configurations)) {
$config = DashboardBlockBase::getBasicConfigStructure();
$config['plugin_id'] = $key;
$block_configurations[$key] = $config;
}
}
else {
// Delete block if deselecte.
if (array_key_exists($key, $block_configurations)) {
unset($block_configurations[$key]);
}
}
}
// Save.
$this->dashboardSettingsService
->saveBlockConfigurations($block_configurations);
}