1

I have a custom entity "Possession" that I created that has a non-standard edit form route to help facilitate a decending url structure. The routing for the edit form looks like this:

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

That seems to be working fine, but now the Delete form isn't working properly. When I click on "delete" the page white screens with this error:

The website encountered an unexpected error. Please try again later.
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 reason that the Delete form would be complaining about the edit form route is that the cancel link on the Delete form directs you to the edit form, so it needs those parameters form the link. I ran into this problem previously with the List Builder page for this entity, but I just fixed it in the code for that page.

For this I tried to edit the PossessionDeleteForm.php file that was generated when I created this entity through Drupal Console. I added a buildForm method to the empty class to a variation of this:

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 throw a ksm() in there to inspect that it seems like it's set up correctly, but it doesn't seem to have any change on the message that I'm recieving on the white screen. I also tried adding the getCancelURL() method to the class with a basic URL:

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

Still nothing.

Next I tried the urlRouteParamters() method in the actual 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. Does anyone have any suggestions?

0

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 '18 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 '18 at 15:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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