Has anyone come across a way to both pass a dynamic route parameter as well as upcasting it?

something like:

$routes["my.custom.route"] = new Route(
    '_controller' => '\Drupal\mymodule\Controller\MyController::view',
    '_title_callback' => '\Drupal\mymodule\Controller\MyController::title',
    'slugs' => '{name}',
    '_permission'  => 'access content',
    'parameters' => array(
      'name' => array(
        'type' => 'entity:my_entity'

This way I could have both the object due to upcasting and the original slug part from the url for use in my controller.

  • Whatever string you pass is used to load the entity, so stands to reason would be available on the entity object itself, no? – Clive Jan 12 '17 at 16:14
  • I am using URL aliases to load a taxonomy term. I got the upcasting working. but I also need the original [term:name] part of the alias. being able to keep track if it was uncategorized vs uncategorized-2. – LittleCoding Jan 12 '17 at 16:34
  • Nut sure what aliases have to do with this, they're resolved before routing matching happens, routing doesn't know anything about aliases. if name is a term, then this only works if you get the ID, which you can always get back again with $entity->id(), and if you generate an alias again, then it will also automatically use the alias again. Maybe you should ask what you actually how to do what you're actually trying to achieve – Berdir Jan 12 '17 at 18:48
  • Path would be something like: /my/custom/route/uncategorized-2. While the term alias path is something like /categories/uncategorized-2. So I have the term's entity object loading via upcasting. But I would like to have the original uncategorized-2 as another parameter of the route and accessible via \Drupal::routeMatch()->getParameter('slugs') – LittleCoding Jan 12 '17 at 19:12

Your Answer

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

Browse other questions tagged or ask your own question.