public function SettingsForm::submitForm in Dynamic Layouts 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 FormInterface::submitForm
File
- src/
Form/ SettingsForm.php, line 131
Class
- SettingsForm
- Provides a generic settings form for the DynamicLayouts.
Namespace
Drupal\dynamic_layouts\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\dynamic_layouts\DynamicLayoutSettingsInterface $settings */
if (!($settings = $this->entityTypeManager
->getStorage('dynamic_layout_settings')
->load('settings'))) {
return NULL;
}
if ($form_state
->getValue(Constants::FRONTEND_LIBRARY) == Constants::BOOTSTRAP) {
$url = Url::fromUri('https://www.drupal.org/project/bootstrap_library');
$link = Link::fromTextAndUrl(t('bootstrap_library'), $url)
->toString();
// Display a message.
$this
->messenger()
->addWarning(t('You have selected Bootstrap, to display the layout properly in the frontend: install the @link module & select version 4.x or implement Bootstrap (v4) in your theme.', [
'@link' => $link,
]));
}
$old_frontend_library = $settings
->getFrontendLibrary();
// Display a message to create a layout,
// only when we had no frontend library.
if (!$old_frontend_library) {
$new_layout_link = Link::fromTextAndUrl(t('click here'), Url::fromRoute('dynamic_layout.dynamic_layout_add'))
->toString();
// Display a message.
$this
->messenger()
->addStatus(t('Settings have been saved, @link to add a Dynamic Layout!', array(
'@link' => $new_layout_link,
)));
}
$new_column_prefix = $form_state
->getValue('column_prefix');
$new_grid_column_count = $form_state
->getValue('grid_column_count');
// Set the form values.
if ($new_frontend_library = $form_state
->getValue(Constants::FRONTEND_LIBRARY)) {
// Get the last column number, we set this after purging the old ones.
$last_column_number = $settings
->getLastColumnNumber($new_frontend_library, $new_column_prefix, $new_grid_column_count);
if ($new_frontend_library == Constants::BOOTSTRAP) {
$new_column_prefix = 'col';
}
$this
->updateValues($new_column_prefix, $new_grid_column_count, $last_column_number, $old_frontend_library, $new_frontend_library, $settings);
}
$settings
->save();
}