 Thank you everyone. Can I get a good evening back? Thank you. I know you all are a little bit sleepy but just be with me for some more time. So thank you for showing up. It's really good to see all these faces and welcome to the beautiful city of Canals and welcome to DrupalCon Amsterdam. Thank you for joining me in my session. The topic for my session is let's take the best route exploring Drupal8 routing system. So I have made this presentation with the help of symphony.com and a drupal.org and try to bring the best of both of the worlds to make sure that it is a good presentation and I would be starting from a very basic level and as I progress I would be using some introductory examples and some screenshots to make sure that the session is well understood and well received by you all. So introducing myself. My name is Surabhi Srival and I work with Srijan Technologies. On Drupal I go by the name S-U-R-B-Z or you can search me in my complete name to locate my profile. On Twitter I go by the handles Surabhi Srival. Don't forget to take this conversation while using my Twitter handle. So at Srijan I am primarily involved with Drupal 7 and Drupal 8 projects which also means that I have worked with teams wherein we have design systems which have used various flavors of Drupal and talking about Srijan. So Srijan is a 15 year old company and when Srijan started it was mainly involved with a lot of non-Drupal stuff like ROR, Python, Django but 45 years later Srijan got its hands dirty with Drupal and now 8 to 9 years later we have a good Drupal name with 200 plus people primarily focused towards Drupal making us Asia's largest Drupal boutique and Srijan has its headquarters in Indiana, New Delhi and we have colleagues working all across the globe. Okay so before I sort of begin I would like to just set the context right here so that we are well aligned on what we are actually going through the presentation while I scan through. So this is sort of an agenda. I would be starting from an overview with the help of an introductory example. We would be seeing the underlying mechanism of routing that is HTTP kernel how Drupal 8 routing is different from Drupal 7. Wherein a Drupal 7 was using hook menu, how Drupal 8 makes users of YML and controllers. We will also see structures of routes, simple access checks using permissions and roles, dynamic routes using patterns and routes and I would conclude this session with the help of a basic summary of what we have talked about. So let's begin. So this picture, what it signifies? Anybody from the audience? A car. A car. Yeah. Okay. Okay so basically you can see a car is a traveling right. So it is starting from some sort of a starting point and reaching some sort of a destination right. So taking some path in between right. Similarly we all have a travel to this Drupal con Amsterdam right. We might have taken same path or we might have taken different paths. Okay so similarly in Drupal a path is defined as a way which returns some sort of font. For example if I say slash node which is the front page of a basic Drupal installation is a route slash node slash edit add which opens up a node add form or I can say node edit page which opens up a node edit form is also a route. Most of us might have got a chance to work with NBC frameworks right. Many of them and some of us might have also worked specifically with Symphony right. For those who have not got a chance to work with Symphony this slide is a very basic slide which outlines how a routing works with Symphony. So if you see in Symphony there is an app controller then there is config directory and then we have a routing file. So blog show is a route and which is mapped to path slash blog. Whenever slash blog is hit then controller name is called and method is involved. This is how routing takes place in Symphony and if I talk of Drupal 7 so when we work with Drupal 7 then routing is handled by a function hook menu and in Drupal 7 this function not only handles routing but it also handles access controls visible navigation so a lot of responsibilities are handled by this function. So there is a table called menu router which stores all the paths and as soon as the request comes in that path is fetched from that table and the corresponding request is fetched. So for those of you who have not got a chance to dig deeper into this table we can just do that right now. Let me just show you use Drupal 7 database. So you see this is what the table is actually formed of. It has fields which are path then access arguments access callbacks. So all these are basically defining the structure of a table. So if I see what this table has in store for us this is a storage section pulled out from this table. So you see so in Drupal 7 this concept was handled by menu router table and anybody who is coming in from an embassy background this sort of a concept towards alien concept right we were not much aware of what was happening behind the scenes. Drupal 8 brings up some sort of a transparency wherein it says goodbye to hook menu. So if you see on the screen this is a very basic implementation of hook menu which was there in Drupal 7 but Drupal 8 is not using this at all and Drupal 8 has said goodbye to the menu. So what Drupal 8 uses then? So Drupal 8 has borrowed is a rounding mechanism from symphony and it makes uses of HTTP kernel. If you want to locate this kernel you can just go on to your Drupal folders inside that is a vendor directory then is a symphony component and you can just dig deeper into the code. How it works at a conceptual level I can just explain you right now. So we have a block diagram here wherein we have four blocks. The request block which is in reading some sort of response. So let's just understand it by focusing on the request block first wherein a request is coming in and this request could be a post or a get request which is coming in from a desktop or mobile device and a response is being generated in the form of HTML or JSON and if a successful response is generated then the status code is 200 else we have a phone on your page. So HTTP kernel is taking in this request and it is generating this response but to do that it is making use of some other systems right and what are these other systems? So these are linux files and controllers which we will see further in the session. Whenever a user is accessing a path then Drupal basically checks if the requirements are being met that is the permission and the role are correct and the requirements are being met then a successful response is generated else we get a phone on for page. So let's just talk about these other systems which facilitate this response generation so we have routing file and we have controllers. Talking about yml file so yml file is nothing but it basically tells Drupal how to behave whenever a particular request is encountered. So this is a very basic implementation of a routing file which is taking module name dot routing dot yml as an naming convention and this route is mapped to the path slash example. So whenever slash example is hit permission access content is checked and if the accessing user has the role of an administrator in this case then example controller is called and content method is invoked and what are controllers so need less to define them it is basically a piece of code which generates some sort of response object. So this is a very basic implementation of a content function which is generating a simple hello world markup and we can place the controllers in SRC controller directory very basic. Now just expanding on a structure of routes so we just had a glance at what the yml file has at a very basic level this is a sort of an extension of that wherein I have kind of extended the requirements so if you see the requirements section you would see there is permission section and there is role section so I have separated permission one with permission two with the help of a comma which defines an all operation and role one is being separated from role two with the help of plus which defines an and operation so just to explain this whenever a user is accessing slash example if he has role content writer and content moderator and has the permission of access content or access user profile then this path would return true example controller would be called and content method would be invoked but systems don't just function on static routes and we do have dynamic routes so this is a very basic implementation of dynamic route where slug is a wildcard place hold up and it can take up any values until and unless defined but here I have defined slug as en or fr so if a user enters the value of slug as en or fr then this route would return true and block show function will be called one thing to notice here is that only the second argument of the path can be dynamic so we cannot do slash slug slash block that is actually not permitted and we should only keep the second arguments of the route to be dynamic then there is also something named params in routes where in if anybody wishes to use the complete entity type then he can do that so user is the name of a complete entity type and if somebody over here enters a user ID and that user ID is existing in the system then in the controller you would be presented with the complete user object which you can leverage and do any sort of coding to help with that so if that is the case when the user exists in the system and if the user does not exist then a phone or footage will be returned so this is a basic implementation where ensure user function is taking the user object and returning some sort of a markup and here in a dollar user you would get the complete user information which you can use for any sort of coding into your system this mechanism is also known as a casting and if you want to go into much more details then you can refer to this link on the screen one thing to notice here is while I was just trying out these things on my local machine some of the changes were not actually reflecting into the system right so this is because there's some sort of caching is being held and if you want to just make sure that the changes are reflected and you don't want to even clear the caches but you just have to rebuild the router information and you can take the help of these useful commands so if you use drush you can use drush environment Drupal service route to build a rebuild and if you're using Drupal control then you can use Drupal router rebuild command and we're talking too much right okay now let's conclude this talk so just to summarize the steps to follow when we define a route name attach a path URL to it decide this URL has to be static or dynamic if dynamic then we might use to sanitize these values because they are not sanitized by default which we can do with the help of some regular expressions like we can define those values to be integers so that user cannot enter any malfunctioning strings and at times we may want to restrict the access which we can do with the help of access checks we have seen that symphony is somebody who is using HTTP kernel and Drupal has borrowed its mechanism from symphony but Drupal is obviously capable of doing much more which symphony is not which is with the help of entity types we can leverage the complete user object this is one other things like access checks defining permissions routes and yeah decoupled a very tight coupling which was present in Drupal menu or Drupal 7 where hook menu was responsible for a lot of functions behind the scenes I have pushed this code to this repository in case you want to have a look you can check this out and just to I just read this code somewhere technology connects us and technology unites us and technology amplifies our power and at Drupal community it can be seen well wherein we are already supporting a lot of people to learn motivating them and achieve something really really good so just keep doing more of this motivational stuff and the fun just does not ends here I have another session on render API in the same room after this session in case you wish to join that you are most welcome and join us for the contributions thank you