You are here

public function CustomStylesEditForm::submitForm in BeautyTips 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

beautytips_manager/src/Form/CustomStylesEditForm.php, line 159

Class

CustomStylesEditForm

Namespace

Drupal\beautytips_manager\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $style = new \stdClass();
  $style->name = $form_state
    ->getValue('name');
  $mapping = beautytips_manager_style_mapping();
  foreach ($form_state
    ->getValue('custom_styles') as $custom_style => $value) {
    if (!is_array($value)) {
      if (isset($mapping['options'][$custom_style])) {
        $style->{$mapping['options'][$custom_style]} = $value;
      }
    }
    else {
      if ($custom_style == 'css-styles') {
        foreach ($value as $css_style => $css_value) {
          if (isset($mapping['css_options'][$css_style])) {
            $style->{$mapping['css_options'][$css_style]} = $css_value;
          }
        }
      }
    }
  }
  if (!is_null($this->style)) {
    $style->id = $this->style->id;
  }
  beautytips_manager_save_custom_style($style);
  \Drupal::cache()
    ->delete('beautytips:beautytips-styles');
  $form_state
    ->setRedirect('beautytips_manager.customStyles');
}