You are here

public function TourTipController::add in Tour UI 8

Provides a creation form for a new tip to be added to a tour entity.

Parameters

\Drupal\tour\Entity\Tour $tour: The tour in which the tip needs to be added to.

string $type: The type of tip that will be added to the tour.

Return value

array A renderable form array.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\Core\Form\EnforcedResponseException

\Drupal\Core\Form\FormAjaxException

File

src/Controller/TourTipController.php, line 85

Class

TourTipController
Handles page returns for tour tip.

Namespace

Drupal\tour_ui\Controller

Code

public function add(Tour $tour, $type = '') {

  // We need a type to build this form.
  if (!$type) {
    throw new NotFoundHttpException();
  }

  // Default values.
  $defaults = [
    'plugin' => Html::escape($type),
    'weight' => $this->requestStack
      ->getCurrentRequest()->query
      ->get('weight'),
  ];

  // Build a new stub tip.
  $stub = $this->tipPluginManager
    ->createInstance($type, $defaults);

  // Attach the tour, tip and if it's new to the form.
  $form_state = new FormState();
  $form_state
    ->setFormState([
    '#tour' => $tour,
    '#tip' => $stub,
    '#new' => TRUE,
  ]);
  return $this->formBuilder
    ->buildForm('\\Drupal\\tour_ui\\Form\\TourTipForm', $form_state);
}