12

I've created a module called hotel_reviews.

I've created the route node/{node}/reviews using hotel_reviews.routing.yml.

hotel_reviews.content:
  path: '/node/{node}/reviews'
  defaults:
    _controller: '\Drupal\hotel_reviews\Controller\ReviewsController::content'
    _title: 'Reviews'
  requirements:
    _permission: 'access content'

I then tried to add a local task using hotel_reviews.links.task.yml.

hotel_reviews.content:
  route_name: hotel_reviews.content
  title: 'Reviews'
  base_route: node.view
  weight: 100

I can now access the content defined by my controller at node/1/reviews, however when I go to node/1 I don't see a reviews tab.

What am I doing wrong?

I've been using the following documentation so far:

1 Answer 1

15

Your base route is wrong. You need to use the route that node uses for /node/1. That's not node.view. It's entity.node.canonical.

3
  • 5
    It's similar to what done from the Tracker module in its tracker.links.task.yml file for the "Activity" tab (/user/{user}/activity) for which the base route is entity.user.canonical. (I added this example as reminder for myself, hoping it will help other users too.)
    – avpaderno
    Commented Apr 29, 2016 at 12:18
  • 1
    This worked great for me. Thanks ... But it's switching away from the admin theme to the front-end theme ... Any thoughts on how to keep it with the admin theme? Thanks! Commented Jul 13, 2018 at 14:24
  • 1
    Nevermind ... found it ... leaving answer here for others: (in route definition) options: _admin_route: TRUE Commented Jul 13, 2018 at 14:31

Your Answer

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

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