Upload
srijan-technologies
View
334
Download
3
Embed Size (px)
Citation preview
Routing in Drupal 8Decoupling hook_menu()
Ashish Thakur @Ashish_Thakur
OverviewA route is a path which is defined for Drupal to return some sort of content on. For example, the default front page, '/node' is a route. When Drupal receives a request, it tries to match the requested path to a route it knows about. If the route is found, then the route's definition is used to return content. Otherwise, Drupal returns a 404.
Overview
Routing in Drupal 7● In Drupal 7 routing is handled by hook_menu().● Apart from just routing it has many other responsibilities to
do➢ Routing➢ Access Control➢ Visible navigation➢ File uploading
● It is too much for a single function to handle and apart from routing many other tasks are tightly coupled in a single function.
● And this looks a bit alien concept to developers from other MVC frameworks.
Routing in Railsmatch 'products/:id', :to => 'catalog#view'
Routing in Symfony# app/config/routing.yml
blog_show:
path: /blog/{slug}
defaults: { _controller: AcmeBlogBundle:Blog:show }
Routing in Drupal 7/** * Implements hook_menu(). */function node_menu() { $items['node/%node/edit'] = array( 'title' => 'Edit', 'page callback' => 'node_page_edit', 'page arguments' => array(1), 'access callback' => 'node_access', 'access arguments' => array('update', 1), 'weight' => 0, 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, 'file' => 'node.pages.inc', );}
Routing in Drupal 8Drupal's routing system works with the Symfony HTTP Kernel.
Routing in Drupal 8● Drupal's routing system works with the Symfony HTTP
Kernel. ● Rather than defining routes in hook_menu(), they are now
defined in module.routing.yml files, in YAML format● An example from node.routing.yml file
entity.node.edit_form: path: '/node/{node}/edit' defaults: _entity_form: 'node.edit' requirements: _entity_access: 'node.update' options: _node_operation_route: TRUE
Decoupling hook_menu()
Useful Links● https://www.drupal.org/developing/api/8/routing● https://www.drupal.org/developing/api/8/menu● https://www.drupal.org/node/1800686● https://www.drupal.org/list-changes
Ashish Thakur@Ashish_Thakur
Thank You!