public function TourForm::tipAdd in Tour UI 8
Submit handler.
File
- src/Form/ TourForm.php, line 271 
Class
- TourForm
- Form controller for the tour entity edit forms.
Namespace
Drupal\tour_ui\FormCode
public function tipAdd($form, FormStateInterface $form_state) {
  $tour = $this
    ->getEntity($form_state);
  $this::submitForm($form, $form_state, FALSE);
  $weight = 0;
  if (!$form_state
    ->isValueEmpty('tips')) {
    // Get last weight.
    foreach ($form_state
      ->getValue('tips') as $tip) {
      if ($tip['weight'] > $weight) {
        $weight = $tip['weight'] + 1;
      }
    }
  }
  $stub = $this->tipPluginManager
    ->createInstance($form_state
    ->getValue('new'), []);
  // If a form is available for this tip then redirect to a add page.
  $stub_form = $stub
    ->buildConfigurationForm([], new FormState());
  if (isset($stub_form)) {
    // Redirect to the appropriate page to add this new tip.
    $form_state
      ->setRedirect('tour_ui.tip.add', [
      'tour' => $tour
        ->id(),
      'type' => $form_state
        ->getValue('new'),
    ], [
      'query' => [
        'weight' => $weight,
      ],
    ]);
  }
}