How to upcast webform submission in custom routes resp. controller?

by Alex   Last Updated January 11, 2019 12:07 PM - source

Using this route:

confirm:
  path: '/node/{node}/submission/{webform_submission}/confirm'
  defaults:
    _controller: '\Drupal\mymodule\Controller\MymoduleController::confirm'
    _title: 'Confirm your submission'
  requirements:
    _permission: 'confirm webform submission'

And visiting node/15/submission/15/confirm I get the error:

RuntimeException: Controller "Drupal\mymodule\Controller\MymoduleController::confirm()" requires that you provide a value for the "$submission" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one. in Symfony\Component\HttpKernel\Controller\ArgumentResolver->getArguments()

What am I doing wrong? Why doesnt it load the submission 15? It does exist.

Tags : 8 routes webforms


Answers 1


You probably just need to declare the parameter type:

confirm:
  path: '/node/{node}/submission/{webform_submission}/confirm'
  defaults:
    _controller: '\Drupal\mymodule\Controller\MymoduleController::confirm'
    _title: 'Confirm your submission'
  requirements:
    _permission: 'confirm webform submission'
  options:
    parameters:
      webform_submission:
        type: entity:webform_submission
Clive
Clive
January 11, 2019 12:02 PM

Related Questions


Return data from WebformHandler to Controller

Updated January 31, 2019 11:07 AM

hook_menu wildcard auto-loader for webform submission?

Updated February 13, 2019 10:07 AM

How do you set a one-off access checker on a route?

Updated December 01, 2016 08:03 AM

add class to LI

Updated December 25, 2016 08:03 AM