10

According to Drupal handbook route definition accepts parameter called _theme. Unfortunately this parameter is documented as "TODO".

Can this be used to force admin theme for the route? Is it possible to inject config parameter with admin theme name here?

It appears that other solution is to use Theme negotiator however the _theme parameter looks very tempting and way simpler to use.

2 Answers 2

19

You're looking for the _admin_route option:

aggregator.feed_add:
  path: '/aggregator/sources/add'
  defaults:
    _controller: '\Drupal\aggregator\Controller\AggregatorController::feedAdd'
    _title: 'Add feed'
  requirements:
    _permission: 'administer news feeds'
  options:
    _admin_route: TRUE
4
  • 3
    Yet another undocumented D8 feature. Commented Dec 29, 2015 at 17:41
  • 9
    Documentation might not be so great yet for D8 but change records are: drupal.org/node/2224207. Always search there if you know how something worked in D7 (found by seaching for "admin path"). drupal.org/developing/api/8/routing seems like a good place (subpage or so) to document this, looking forward to the documentation you'll write about this :)
    – Berdir
    Commented Dec 29, 2015 at 17:47
  • 1
    so does _admin_route just change it so it uses the default theme instead of the admin one?
    – Amy
    Commented Jun 20, 2017 at 14:09
  • 1
    I get a InvalidArgumentException: Routing requirement for "options" must be a string. when attempting to use this solution
    – Amy
    Commented Jun 20, 2017 at 14:30
5
module.myroute:
  path: '/path/path2'
  defaults:
    _controller: 'Drupal\module\Controller\MyController::add'
    _title: 'Add element'
  options:
    _admin_route: 'TRUE'

You need to use ' ' around TRUE, if not, you will get 'InvalidArgumentException: Routing requirement for "options" must be a string'

1

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.