Can I create a form with a route like this /rooms/{node.alias}/booking? I'm working on a booking project and I have to create a form for reservations.

I have created the accommodation content type and the url_alias for this is: /rooms/[node:title]

Example:


/node/1 = /rooms/1-accommodation-example
/node/2 = /rooms/2-accommodation-example


I need to know if I can do this:

booking.booking_form:
  path: 'booking/{url_alias}'
  defaults:
    _form: '\Drupal\booking\Form\BookingForm'
    _title: 'Accommodation booking'
  requirements:
    _access: 'TRUE'


Is this possible? path: 'booking/{url_alias}' or path: '{url_alias}/booking'

What happen next, if you try yo go to this route:


/booking/any-text-asdasdas = the form page is loaded.
/booking/rooms = the form page is loaded.
/booking/rooms/1-accommodation-example = page not found.


I tried but I don't know how to find information about this way of routing.

I don't know if I have explained what I need well, any information will be very helpful.

Thanks,STF
Is this possible? path: 'booking/{url_alias}' or path:
  '{url_alias}/booking'


path: '{url_alias}/booking' paths can never start with a slug/placeholder. 

You'll have to use path: 'booking/{url_alias}'

In your form:

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $url_alias = NULL) {

    // Some DB query to check if $url_alias is the 2nd path of an alias.
    // In other words, check if "/rooms/$url_alias" exists.

    if ($db_query == false) { // if $url_alias is not the 2nd path of an alias.
       throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
    }

    // Your Form code goes here

    return $form;
  }