public function GinLoginConfigurationForm::submitForm in Gin Login 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/ GinLoginConfigurationForm.php, line 163
Class
- GinLoginConfigurationForm
- Class SettingsForm.
Namespace
Drupal\gin_login\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$values = $form_state
->getValues();
$file_system = \Drupal::service('file_system');
$default_scheme = $this
->config('system.file')
->get('default_scheme');
$config = $this
->config('gin_login.settings');
try {
if (!empty($values['logo_upload'])) {
$filename = $file_system
->copy($values['logo_upload']
->getFileUri(), $default_scheme . '://');
$values['default_logo'] = 0;
$values['logo_path'] = $filename;
}
} catch (FileException $e) {
// Ignore.
}
try {
if (!empty($values['brand_image_upload'])) {
$filename = $file_system
->copy($values['brand_image_upload']
->getFileUri(), $default_scheme . '://');
$values['default_brand_image'] = 0;
$values['brand_image_path'] = $filename;
}
} catch (FileException $e) {
// Ignore.
}
unset($values['logo_upload']);
unset($values['favicon_upload']);
// If the user entered a path relative to the system files directory for
// a logo store a public:// URI so the theme system can handle it.
if (!empty($values['logo_path'])) {
$values['logo_path'] = $this
->validatePath($values['logo_path']);
}
// If the user entered a path relative to the system files directory for
// a brand images, store a public:// URI so the theme system can handle it.
if (!empty($values['brand_image_path'])) {
$values['brand_image_path'] = $this
->validatePath($values['brand_image_path']);
}
foreach ($values as $key => $value) {
if ($key == 'default_logo') {
$config
->set('logo.use_default', $value);
}
elseif ($key == 'logo_path') {
$config
->set('logo.path', $value);
}
elseif ($key == 'default_brand_image') {
$config
->set('brand_image.use_default', $value);
}
elseif ($key == 'brand_image_path') {
$config
->set('brand_image.path', $value);
}
}
$config
->save();
// Rebuild the router.
\Drupal::service('router.builder')
->rebuild();
}