public function SocialMediaAdminForm::submitForm in Social media share 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/ SocialMediaAdminForm.php, line 194
Class
- SocialMediaAdminForm
- Class SocialMediaAdminForm.
Namespace
Drupal\social_media\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$socials = $this
->getSocialMedias();
$config = $this
->config('social_media.settings');
$config
->clear('social_media.settings');
foreach ($socials as $social => $media) {
if ($form_state
->hasValue($social . '_enable')) {
$config
->set('social_media.' . $social . '.enable', $form_state
->getValue($social . '_enable'));
}
if ($form_state
->hasValue($social . '_api_url')) {
$config
->set('social_media.' . $social . '.api_url', $form_state
->getValue($social . '_api_url'));
}
if ($form_state
->hasValue($social . '_api_event')) {
$config
->set('social_media.' . $social . '.api_event', $form_state
->getValue($social . '_api_event'));
}
if ($form_state
->hasValue($social . '_drupalSettings')) {
$config
->set('social_media.' . $social . '.drupalSettings', $form_state
->getValue($social . '_drupalSettings'));
}
if ($form_state
->hasValue($social . '_library')) {
$config
->set('social_media.' . $social . '.library', $form_state
->getValue($social . '_library'));
}
if ($form_state
->hasValue($social . '_text')) {
$config
->set('social_media.' . $social . '.text', $form_state
->getValue($social . '_text'));
}
if ($form_state
->hasValue($social . '_default_img')) {
$config
->set('social_media.' . $social . '.default_img', $form_state
->getValue($social . '_default_img'));
}
if ($form_state
->hasValue($social . '_img')) {
$config
->set('social_media.' . $social . '.img', $form_state
->getValue($social . '_img'));
}
if ($form_state
->hasValue($social . '_weight')) {
$config
->set('social_media.' . $social . '.weight', $form_state
->getValue($social . '_weight'));
}
if ($form_state
->hasValue($social . '_attributes')) {
$config
->set('social_media.' . $social . '.attributes', $form_state
->getValue($social . '_attributes'));
}
if ($form_state
->hasValue($social . '_enable_forward')) {
$config
->set('social_media.' . $social . '.enable_forward', $form_state
->getValue($social . '_enable_forward'));
}
if ($form_state
->hasValue($social . '_show_forward')) {
$config
->set('social_media.' . $social . '.show_forward', $form_state
->getValue($social . '_show_forward'));
}
}
$config
->save();
$this
->messenger()
->addMessage($this
->t('Your configuration has been saved'));
}