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

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

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


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