Create route with default param in Drupal 8

by Yogesh   Last Updated April 15, 2019 08:07 AM

I've a custom route and form, form input field(s) slightly changes based on arguments passed to it. There are only 2 possible arguments can be passed in URL. I'm using current latest version of Drupal 8 i.e. 8.6.14.

Following is copy of route from module:

mymodule.form:
  path: '/mymodule/{url_option}'
  defaults:
    _form: '\Drupal\mymodule\Form\ModuleForm'
    url_option: 'custom'
  requirements:
    _permission: 'access content'
    url_option: '^[a-zA-Z]*'

The above was working with earlier version of Drupal (It stopped working recently after updating to 8.6.x).

Issue : When I try to access this form using "mymodule" it shows page not found. I must need to pass argument to access form i.e. "/mymodule/custom". Also when I try to add a menu item (using "Admin => Structure => Menu") for this route, I get following error. I've tried both "/mymodule" and "/mymodule/custom".

The website encountered an unexpected error. Please try again later.Drupal\Core\Entity\EntityStorageException: The "url_option" entity type does not exist.

I've also tried implementing ParamConverter, but that didn't worked either. And since there are only 2 possible arguments user can pass, I'm not creating it an entity.

Tags : 8 routes


Related Questions


Updated December 01, 2016 08:03 AM

Updated December 25, 2016 08:03 AM

Updated December 09, 2016 08:03 AM

Updated January 10, 2017 08:03 AM