0

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.

Edit: this is my Controller, the second argument is always null:

<?php

namespace Drupal\mymodule\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\Controller\EntityViewController;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Entity\EntityInterface;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\webform\WebformSubmission;

/**
 * @todo
 */
// class MymoduleController extends ControllerBase { // doesnt make a difference
class MymoduleController extends EntityViewController {
  public function confirm(EntityInterface $node = null, EntityInterface $submission = null) {

    debug($submission);

    $response = new Response( 'test' );

    return $response;
  }
}

1 Answer 1

3

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

The parameter names also need to match, so update your controller accordingly:

public function confirm(EntityInterface $node = null, EntityInterface $webform_submission = null) {
6
  • doesnt work unfortunately, the 2nd parameter is always NULL. if i look in how webform handles it itself (WebformSubmissionViewController::view) i wonder if this is even possible. should be though, since its a regular entity, isnt it?
    – Alex
    Commented Jan 11, 2019 at 12:05
  • ive updated my code.
    – Alex
    Commented Jan 11, 2019 at 12:15
  • You should also set the type hint the entity type interface. confirm(NodeInterface $node = NULL, WebformSubmissionInterface $submission = NULL)
    – jrockowitz
    Commented Jan 11, 2019 at 12:18
  • @jrockowitz i had like that initially, but it doesnt work either. i switched to entityinterface bc thats how webform does it itself. thanks though
    – Alex
    Commented Jan 11, 2019 at 12:20
  • 1
    Symfony is sensitive to the parameter name @Alex - make sure it’s the same in the routing file and the controller.
    – Clive
    Commented Jan 11, 2019 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.