You are here

public function CustomTipsEditForm::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/CustomTipsEditForm.php, line 221

Class

CustomTipsEditForm

Namespace

Drupal\beautytips_manager\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $tip = $form_state
    ->getValue('tip');
  $positions = [];
  foreach ($tip['positions'] as $position => $order) {
    if ($order !== '') {
      while (isset($positions[$order])) {
        $order++;
      }
      $positions[$order] = $position;
    }
  }
  ksort($positions);
  $tip['positions'] = count($positions) ? implode(',', $positions) : '';
  beautytips_manager_save_custom_tip($tip);
  \Drupal::cache()
    ->delete('beautytips:beautytips-ui-custom-tips');
  $form_state
    ->setRedirect('beautytips_manager.customTips');
}