You are here

public function SiteBannerConfigurationForm::submitForm in Site Banner 8

Same name and namespace in other branches
  1. 2.0.x src/Form/SiteBannerConfigurationForm.php \Drupal\site_banner\Form\SiteBannerConfigurationForm::submitForm()
  2. 1.0.x src/Form/SiteBannerConfigurationForm.php \Drupal\site_banner\Form\SiteBannerConfigurationForm::submitForm()

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/SiteBannerConfigurationForm.php, line 113

Class

SiteBannerConfigurationForm
Class SiteBannerConfigurationForm.

Namespace

Drupal\site_banner\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);
  $config = $this->configFactory
    ->getEditable('site_banner.settings');
  $config
    ->set('site_banner_text', $form_state
    ->getValue('site_banner_text'));
  $config
    ->set('status', $form_state
    ->getValue('status'));
  $config
    ->set('show_footer', $form_state
    ->getValue('show_footer'));
  $config
    ->set('show_header', $form_state
    ->getValue('show_header'));
  $config
    ->set('site_banner_color', $form_state
    ->getValue('site_banner_color'));
  if (!$form_state
    ->getValue('status')) {
    $config
      ->set('site_banner_start_date', NULL);
    $config
      ->set('site_banner_end_date', NULL);
    $config
      ->save();
    return;
  }
  if ($form_state
    ->getValue('site_banner_start_date')) {
    $config
      ->set('site_banner_start_date', $form_state
      ->getValue('site_banner_start_date')
      ->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT));
  }
  if ($form_state
    ->getValue('site_banner_end_date')) {
    $config
      ->set('site_banner_end_date', $form_state
      ->getValue('site_banner_end_date')
      ->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT));
  }
  $config
    ->save();
}