[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu

  • Published on
    17-Jul-2015

  • View
    333

  • Download
    3

Transcript

<ul><li><p>Routing in Drupal 8Decoupling hook_menu()</p><p>Ashish Thakur @Ashish_Thakur</p></li><li><p>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.</p></li><li><p>Overview</p></li><li><p>Routing in Drupal 7 In Drupal 7 routing is handled by hook_menu(). Apart from just routing it has many other responsibilities to </p><p>do Routing Access Control Visible navigation File uploading</p><p> It is too much for a single function to handle and apart from routing many other tasks are tightly coupled in a single function.</p><p> And this looks a bit alien concept to developers from other MVC frameworks.</p></li><li><p>Routing in Railsmatch 'products/:id', :to =&gt; 'catalog#view'</p></li><li><p>Routing in Symfony# app/config/routing.yml</p><p>blog_show:</p><p> path: /blog/{slug}</p><p> defaults: { _controller: AcmeBlogBundle:Blog:show }</p></li><li><p>Routing in Drupal 7/** * Implements hook_menu(). */function node_menu() { $items['node/%node/edit'] = array( 'title' =&gt; 'Edit', 'page callback' =&gt; 'node_page_edit', 'page arguments' =&gt; array(1), 'access callback' =&gt; 'node_access', 'access arguments' =&gt; array('update', 1), 'weight' =&gt; 0, 'type' =&gt; MENU_LOCAL_TASK, 'context' =&gt; MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, 'file' =&gt; 'node.pages.inc', );}</p></li><li><p>Routing in Drupal 8Drupal's routing system works with the Symfony HTTP Kernel. </p></li><li><p>Routing in Drupal 8 Drupal's routing system works with the Symfony HTTP </p><p>Kernel. Rather than defining routes in hook_menu(), they are now </p><p>defined in module.routing.yml files, in YAML format An example from node.routing.yml file</p><p>entity.node.edit_form: path: '/node/{node}/edit' defaults: _entity_form: 'node.edit' requirements: _entity_access: 'node.update' options: _node_operation_route: TRUE</p></li><li><p>Decoupling hook_menu()</p></li><li><p>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</p></li><li><p>Ashish Thakur@Ashish_Thakur</p><p>Thank You!</p></li></ul>

Recommended

View more >