0

Can i use route ID for Link template 'edit-form' for entity type?

I'm following this tutorial

over there he use:

 *   links = {
 *     "edit-form" = "flower.edit",
 *     "delete-form" = "flower.delete"
 *   }

while flower.edit (i assume) is from below route.yml:

flower.edit:
  path: '/admin/structure/flowers/edit/{flower}'
  defaults:
    _entity_form: 'flower.edit'
    _title: 'Edit flower'
  requirements:
    _permission: 'administer site configuration'

but when i run, it throw me an error:

Uncaught PHP Exception Drupal\Core\Entity\Exception\InvalidLinkTemplateException: "Link template 'edit-form' for entity type 'flower' must start with a leading slash, the current link template is 'flower.edit'" at \core\lib\Drupal\Core\Entity\EntityTypeManager.php line 97

I know i can just use: /admin/structure/flowers/edit/{flower} to solve my problem.

but the question is: is it actually possible to use route (instead of path) in entity links config?

3
  • The tutorial is from 2014, since then the form links have changed from routes to paths.
    – 4uk4
    Mar 26, 2017 at 14:35
  • so, the answer is: not possible, it can only accept paths?
    – AnD
    Mar 26, 2017 at 14:37
  • 1
    See change record drupal.org/node/2382937
    – 4uk4
    Mar 26, 2017 at 14:42

1 Answer 1

2

The tutorial is from 2014. Since then the link templates have changed from route to path. See change record:

Previous link template format

   links = {
     "canonical" = "entity.node.canonical",
     "edit-form" = "entity.node.edit_form",
     "delete-form" = "entity.node.delete_form",
   }

New link template format

After the change, the path is used.

   links = {
     "canonical" = "/node/{node}",
     "edit-form" = "/node/{node}/edit",
     "delete-form" = "/node/{node}/delete",
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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