6

Lets say I have these paths:

/admin
/admin/settings
/admin/settings/myentities
myentity/id
/admin/settings/myentities/id/edit
/admin/settings/myentities/id/delete

What would be the proper route names for each one of them?

My current usage is this:

admin

/admin

admin.settings

/admin/settings

admin.settings.myentities OR admin.myentities

/admin/settings/myentities

myentit OR myentity.view

/myentity/id

myentity.edit OR admin.myentities.edit OR admin.settings.myentities.edit

/admin/settings/myentities/id/edit

The things I mostly not sure about is whether I should use the path structure for the route name or not(ie. /path/to/some/where => path.somewhere OR path.to.some.where) and when it comes to entities if I should use admin.myentities + admin.myentities.myentity OR admin.myentity.edit) etc..

1 Answer 1

10

By design, the route name should NOT mirror the path. You want to be able to change the path without breaking the route name, which is why other code in the system should refer to the route name only, not the path. Having a route name that maps directly to the path is akin to a CSS class named .left-align-blue :-)

Some of these conventions are still shaking out. However, for the typical case the recommended pattern is $module_name.$something_meaningful. So in your mymodule module, you'd have routes like:

mymodule.settings
mymodule.advanced_settings
mymodule.status_page

And so on. Note those tell you little about the path. That's by design, as above.

For entities it's a little bit trickier since core has the advantage that most entities are the same name as the module. Contrib doesn't always have that. I would recommend either $entityname.$operation or $module_name.$entityname_$operation. (I don't think core has any double-period route names at present, but I could be wrong.)

So if I were writing a module with a new entity called "nerd" (it's a candy site), I'd have:

nerd.view (for the page that lets you view a nerd)
nerd.edit (for the edit page)
nerd.delete (for the delete confirmation page)

And so on. Make sense?

2
  • we should be really strict to never expect anything about the route name, even I fear that we can't keep that on the entity routes. Apr 19, 2014 at 16:47
  • 1
    why nerd.view why not just nerd? doesn't that imply that there is something on nerd too?
    – user21641
    Apr 19, 2014 at 18:55

Your Answer

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