You are here

public function AddBannerForm::submitForm in Dynamic Banner 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/forms/AddBannerForm.php, line 317

Class

AddBannerForm

Namespace

Drupal\dynamic_banner\forms

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  //define a sort of struct array for display mode for form translation

  //$mode_struct = array('normal', 'time_based', 'rotating', 'fade');

  // extra validation check to make sure
  if ($form_state
    ->getValue('image_type') == t('Use Existing Image(s)')) {
    $imgurl = $form_state
      ->getValue('imgurl');
  }
  else {
    $imgurl = NULL;
  }
  if ($form_state
    ->getValue('image_type') == t('Upload New Image(s)')) {
    $imgfid = $form_state
      ->getValue('image');
  }
  else {
    $imgfid = NULL;
  }
  $path = $form_state
    ->getValue('path');
  $text = $form_state
    ->getValue('text');
  $link = $form_state
    ->getValue('link');
  $mode = $form_state
    ->getValue('mode');
  $dbid = $form_state
    ->getValue('dbid');
  $time_on = NULL;
  $time_off = NULL;

  // Save the banner
  $this
    ->dynamic_banner_set_banner($path, $imgurl, $imgfid, $text, $link, $mode, $time_on, $time_off, $dbid);
  $this
    ->messenger()
    ->addStatus(t('The banner has been saved.'));
  $form_state
    ->setRedirect('cdb.listbanners');
  return;
}