I have a custom entity (Possession) which has a non-standard edit form. The route for the edit form is the following.

path: '/individual/{individual}/possession/{possession}/edit'
  _entity_form: 'possession.edit'
  _title: 'Edit Possession'
  _permission: 'access administration pages'
  _admin_route: FALSE 
      type: entity:individual
      type: entity:possession

That seems to work fine. Instead, the delete form doesn't work. When I click on delete, I get the following exception.

Symfony\Component\Routing\ExceptionMissingMandatoryParametersException: Some mandatory parameters are missing ("individual") to generate a URL for route "entity.possession.edit_form". in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 182 of core/lib/Drupal/Core/Routing/UrlGenerator.php).

After a little bit of digging, I noticed that the cancel link on the delete form redirects users to the edit form, which needs those parameters. I ran into this problem with the List Builder page, but I just fixed it in the code for that page.

I tried to edit the PossessionDeleteForm.php file that was generated from Drupal Console. I added a buildForm() method.

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $entity = $this->entity;

  $form['actions']['cancel']['#url'] =  Url::fromRoute('entity.possession.edit_form', [
  'possession' => $entity->id(),
  'individual' => $entity->get('individual_id')->target_id,
  return $form; 

If I use ksm() to inspect the form, it seems it's setup correctly, but it doesn't change the thrown exception. I also tried adding the getCancelURL() method to the class with a basic URL, but it didn't fix the error.

public function getCancelURL() {
  return new Url('system.admin_content');

Next I tried the urlRouteParamters() method in the entity class.

protected function urlRouteParameters($rel) {
  $uri_route_parameters = parent::urlRouteParameters($rel);
  if ($rel === 'edit_form') {   
    $uri_route_parameters['individual'] = $this->get('individual_id')->target_id;

  return $uri_route_parameters;

That also didn't work. I have no idea what else to do here.

What is the correct way to redirect users to the edit form, when deleting the entity is cancelled?

1 Answer 1


The relationship is the key of the url relationships, aka edit-form, not edit_form. Try that in urlRouteParameters() and what you are doing should work.

  • That didn't seem to help. It seems like that will work everywhere except on the delete form, which is still throwing a white screen with that same error. It seems like nothing is affecting this.
    – A.J.
    Apr 23, 2018 at 14:33
  • might be because of local tasks.. but I'm not sure why you only do that for edit and not for view and delete too in which case it should work..
    – Berdir
    Apr 23, 2018 at 15:53

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.