2

In my module, I have defined the following route:

custom_module_page:
path: 'new/post/{term-id}'
defaults:
    _controller: '\Drupal\mymodule\Controller\myModuleArticleController::content'
requirements:
    _permission: 'access content'

options:
parameters:
  term-id:
    type: 'term:tid'

in the controller

class myModuleArticleController extends ControllerBase
{ 
public function content(  TermInterface $term = null , Request $request) {

      $term_object = \Drupal\taxonomy\Entity\Term::load($term);

      print_r ($term_object)

this code works now, but instead of "term-id" in path , I want to use term slug in path

custom_module_page:
path: 'new/post/{term-name}' // **this will be term slug ( ex: my-taxonomy-name )**
defaults:
_controller: '\Drupal\mymodule\Controller\myModuleArticleController::content'
requirements:
_permission: 'access content'

options:
parameters:
 term-name:
   type: 'term:name'// **is this right? term name**

and what should i do in controller to get taxonomy id from taxonomy-slug?

  • 1
    You should use an alias. search for the path auto module. – Eyal Jun 7 '16 at 10:48

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.