function SettingsForm::submitForm
Same name in this branch
- 10 core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::submitForm()
Same name in other branches
- 9 core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::submitForm()
- 9 core/modules/aggregator/src/Form/SettingsForm.php \Drupal\aggregator\Form\SettingsForm::submitForm()
- 8.9.x core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::submitForm()
- 8.9.x core/modules/aggregator/src/Form/SettingsForm.php \Drupal\aggregator\Form\SettingsForm::submitForm()
- 11.x core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::submitForm()
- 11.x core/modules/navigation/src/Form/SettingsForm.php \Drupal\navigation\Form\SettingsForm::submitForm()
Overrides ConfigFormBase::submitForm
File
-
core/
modules/ navigation/ src/ Form/ SettingsForm.php, line 183
Class
- SettingsForm
- Configure Navigation settings for this site.
Namespace
Drupal\navigation\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) : void {
$config = $this->config('navigation.settings');
// Get the previous config settings.
$previous_logo_provider = $config->get('logo_provider');
$logo_managed = $config->get('logo_managed');
$previous_logo_fid = $logo_managed ? reset($logo_managed) : NULL;
// Get new values from the form.
$new_logo_provider = $form_state->getValue('logo_provider');
$logo = $form_state->getValue('logo_managed');
$new_logo_fid = !empty($logo) ? reset($logo) : NULL;
// Pre-load files if any for FileUsageInterface.
$previous_logo_managed = $previous_logo_fid ? File::load($previous_logo_fid) : NULL;
$new_logo_managed = $new_logo_fid ? File::load($new_logo_fid) : NULL;
// Decrement if previous logo_provider was 'custom' and has changed to a
// different fid and there's a change in the logo fid.
if ($previous_logo_provider === NavigationRenderer::LOGO_PROVIDER_CUSTOM && ($new_logo_provider !== NavigationRenderer::LOGO_PROVIDER_CUSTOM || $previous_logo_fid !== $new_logo_fid) && $previous_logo_managed) {
$this->fileUsage
->delete($previous_logo_managed, 'navigation', 'logo', 1);
}
// Increment usage if different from the previous one.
if ($new_logo_managed && $new_logo_fid !== $previous_logo_fid) {
$new_logo_managed->setPermanent();
$new_logo_managed->save();
$this->fileUsage
->add($new_logo_managed, 'navigation', 'logo', 1);
}
$config->set('logo_provider', $form_state->getValue('logo_provider'))
->set('logo_managed', $form_state->getValue('logo_managed'))
->save();
parent::submitForm($form, $form_state);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.