Score:0

Custom entity with dynamic paths

eg flag

I am creating a new entity and would like it to be in the users profile.

The path should be "/user/{user-id}/documents/X":

/*
 *   links = {
 *     "canonical" = "/user/{user}/documents/{document}",
 *     "add-form" = "/user/{user}/documents/add",
 *     "edit-form" = "/user/{user}/documents/{document}/edit",
 *     "delete-form" = "/user/{user}/documents/{document}/delete",
 *     "collection" = "/user/{user}/documents",
 *   },
 */

When I enter any page, the following error appears.

Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("user") to generate a URL for route "entity.document.collection". in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 182 of /var/www/html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php).

I have also tried to create the routing.yml file but it still gives the same error.

entity.document.collection:
  path: '/user/{user}/documents'
  defaults:
    _entity_list: 'document'
    _title: 'Document List'
  requirements:
    _permission: 'access content'
  options:
    parameters:
      user:
        type: entity:user

Is there any way to achieve what I want?

apaderno avatar
us flag
As side note, A route like */user/{user}/documents/{document}/edit* or */user/{user}/documents/{document}/delete* is wrong: An entity is unequivocally identified by its ID value, not by the ID for the user who created it and the entity ID. Even nodes have an owner, but the route to delete a node isn't */user/{user}/nodes/{node}/delete*.
apaderno avatar
us flag
If you want to have a tab for each user to show the documents created by that user, that is fine, but */user/{user}/documents/{document}* should not be the canonical route for an entity, IMO.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.