I have nodes whose content type is X that I would like to render differently based on the node path. I'd like to use the default view mode for a path alias and a custom view mode for the other path alias. These aliases were created using the Pathauto module; both of them point to the same node.
- /url/alias1/path => /node/123 (default view mode)
- /url/alias2/path => /node/123 (custom view mode)
I tried using mymodule.routing.yml to do this, but it does not appear to be picked up by the route system.
mymodule.program:
path: '/url/alias2/path'
defaults:
_controller: '\Drupal\mymodule\Controller\RoutesController::setViewMode'
requirements:
_access: 'TRUE'
When I click on the alias with the custom view mode, I get the default view mode. I put a logger statement in the routes controller setViewMode function and it is not reached. This suggests that the routing is not being 'tripped'.
Am I missing something or trying to do something Drupal 8 cannot handle?
I looked at Routing and path aliases but that doesn't quite address my question.