SlideShare a Scribd company logo
Exploring Drupal 8 Routing
System
Surbhi Sriwal | Drupal Developer, Srijan Technologies
#SrijanWW | @srijan
#SrijanWW | @srijan
Surbhi Sriwal
Drupal Developer at Srijan Technologies
https://www.drupal.org/u/surbz
@surbhisriwal
Whoami
#SrijanWW | @srijan
Srijan | Global Open Source leaders
15
Years of
profitable Growth
200+
Largest Drupal
Company in Asia
Pacific Region
45+
Certified
Drupal Engineers
12
Multi-year Global
Customers
Asia’s Largest & Top 10 Worldwide
#SrijanWW | @srijan
Agenda
What next?
● Overview - with an introductory example
● Underlying mechanism of routing - HTTP Kernel
● How is Drupal 8 routing different from tightly coupled Drupal 7 hook_menu()
● How Drupal 8 makes use of yml and controller
● Structure of Routes
● Precedence of same routes
● Simple access checks using permissions and roles
● Dynamic routes and using params in routes
● Some Code
#SrijanWW | @srijan
Introduction
#SrijanWW | @srijan
What is a Route in Drupal?
In Drupal route is a way defined that would return some sort of content.
Example: /node the default front page is a route.
/node/add
/node/{nid}/edit
#SrijanWW | @srijan
Routing In Symfony
In Symfony we have
#app/config/routing.yml
blog_show:
path: /blog
defaults: {_controller: ControllerName:method}
#SrijanWW | @srijan
In Drupal 7 routing is handled by hook_menu().
Apart from just routing it had many other responsibilities to do
● Routing
● Access Control
● Visible Navigation
In Drupal 7 we have menu_router table
This table stores all the paths.
As soon as the request comes - the path is fetched from this table and corresponding
request is fetched.
How is it different from Drupal 7?
#SrijanWW | @srijan
It’s too much for a single function to handle and made some sort of a tight coupling
It looks a much of alien concept to developers coming from other MVC frameworks
How is it different from Drupal 7?
#SrijanWW | @srijan
D8: Goodbye hook_menu()
#SrijanWW | @srijan
D8:The Underlying Mechanism Of Routing
Drupal 8 has adopted its routing from Symfony.
What happens when drupal receives a request - HTTP Kernel
How Drupal does all this ?
#SrijanWW | @srijan
Symfony HTTP Kernel
You can have a look in the Drupal code where this Symfony Kernel lies by going to
<drupal folder>/vendor/symfony/http-kernel/
#SrijanWW | @srijan
Symfony HTTP Kernel
Drupal System uses this HTTP Kernel which gets the request and asks other systems to
produce o/p what are these other systems lets see
#SrijanWW | @srijan
Drupal 8 makes use of yml and controllers
Drupal System uses this HTTP Kernel which gets the request and asks other systems to
produce o/p
These other systems are
Routing File
.routing.yml
Controller
#SrijanWW | @srijan
<modulename>.routing.yml
YML file tells Drupal how to behave when a particular path is encountered.
If you want to specify a default value, you put it into the defaults array. In the same yml array
you specify the class and method connected with '::' to tell the system where to look up stuff.
YML Files
#SrijanWW | @srijan
ExampleController.php - Inside src/Controller/
Controller is a piece of code that is responsible
to generate the response object.
The key concept is the controller which gets
some parameters from the system and converts
them to the response.
So everything without an underscore is
considered to be a parameter to the controller.
Every other property has nothing to do with the
controller parameters and so are considered to
be internal and so have an underscore as prefix.
Controllers
#SrijanWW | @srijan
How exactly hook_menu() was decoupled?
#SrijanWW | @srijan
This was an introductory example now let's explore some more options along with routes so that
we can play around a bit later.
I have tried to cover the examples by referring Symfony docs along with Drupal docs and have tried
to bring a combination altogether.
Drupal can do a lot more than Symfony like access checks based on permissions and roles I have
tried to cover that too, let’s see them one by one ...
Structure Of Routes
#SrijanWW | @srijan
Structure Of Routes
#SrijanWW | @srijan
Whenever you have a {placeholder} in your route path, that portion becomes a wildcard: it
matches any value. Your controller can now also have an argument called $placeholder (the
wildcard and argument names must match).
Dynamic routes - path is a required param it can have static or dynamic arguments
Note that the first item of the path must not be dynamic
To limit - {slug} can be restricted by defining requirements
Dynamic Routes
#SrijanWW | @srijan
When two routes match the same URL, the first route that's loaded wins.
Unfortunately, that means that /blog/test will match the blogshow and not eventshow.
No good!
To fix this, add a requirement was added.
Precedence of same routes
#SrijanWW | @srijan
If you want to get access to an entity type you can use named params in the url.$user is the
name of an entity type.
If the userid does not exist drupal would give a 404.
Named parameters are not sanitized by default.This means that you really should sanitize all
values prior to use.
You can somewhat decrease a code injection security concern by specifying regex
requirements.
Inside the controller you will have access to the the complete user object
Named Params In Route
#SrijanWW | @srijan
Inside the controller you will have access to the the complete user object which can be used
as per the logic.
Named Params In Route
#SrijanWW | @srijan
You don't want to take care about loading an entity, see /user/{user} as example.
For entities you basically just use the name of the entity type and it will execute a entity_load
with the ID passed in the URL. Param converter manager
Upcasting
#SrijanWW | @srijan
Enough Talk
#SrijanWW | @srijan
Show Me The Code
#SrijanWW | @srijan
Showcase
#SrijanWW | @srijan
While working with routing If you update a routes file in Drupal 8 how do you clear the cache?
So instead of clearing caches you can rebuild the router table
If you use drush
drush ev 'Drupal::service("router.builder")->rebuild();'
to rebuild the routing information without clearing all the caches.
If you use drupal console
drupal router:rebuild
Some Useful Commands
#SrijanWW | @srijan
https://github.com/surbz/routing
You can checkout this code from github
#SrijanWW | @srijan
Conclusion
1 So the steps should be define a route name
Attach a path / url to it
Decide this url has to be static or dynamic
If dynamic we might want to sanitize this value before it passes to controller this can
be achieved by restricting the type of input like a regex
At times we may not want all the users to access routes and may want to limit access
We have seen how Symfony routing works using HTTP Kernel
and how Drupal 8 makes use of it.
We have seen Drupal can do more that what was available in Symfony.It can put
access checks based on roles and permissions which is something very specific to
Drupal itself.
3
2
Drupal 8 has decoupled the tight coupling we had with Drupal 74
#SrijanWW | @srijan
Know More
Thank You
@surbhisriwal
www.srijan.net

More Related Content

Similar to [Srijan Wednesday Webinars] Let’s Take the Best Route - Exploring Drupal 8 Routing System

introduction to Laravel and its Basic and origin
introduction to Laravel and its Basic and originintroduction to Laravel and its Basic and origin
introduction to Laravel and its Basic and origin
Karthik Rohan
 
Memphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basicsMemphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basics
Joe Ferguson
 
Final dependency presentation.odp
Final dependency presentation.odpFinal dependency presentation.odp
Final dependency presentation.odp
Srijan Technologies
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
manugoel2003
 
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
Srijan Technologies
 
[Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
 [Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr... [Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
[Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
Srijan Technologies
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
DrupalMumbai
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Udaya Kiran
 
Laravel
LaravelLaravel
Laravel
biplob04
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Mir Nazim
 
Coder Presentation Szeged
Coder Presentation SzegedCoder Presentation Szeged
Coder Presentation SzegedDoug Green
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Dilouar Hossain
 
[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8
[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8
[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8
Srijan Technologies
 
EdTechJoker Spring 2020 - Lecture 7 Drupal intro
EdTechJoker Spring 2020 - Lecture 7 Drupal introEdTechJoker Spring 2020 - Lecture 7 Drupal intro
EdTechJoker Spring 2020 - Lecture 7 Drupal intro
Bryan Ollendyke
 
Semalt: 3 Steps To PHP Web Page Scraping Web
Semalt: 3 Steps To PHP Web Page Scraping WebSemalt: 3 Steps To PHP Web Page Scraping Web
Semalt: 3 Steps To PHP Web Page Scraping Web
ilovemyindia18
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Aaron Schram
 
A deep dive into Drupal 8 routing
A deep dive into Drupal 8 routingA deep dive into Drupal 8 routing
A deep dive into Drupal 8 routing
Naveen Valecha
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
Rodrigo Prates
 

Similar to [Srijan Wednesday Webinars] Let’s Take the Best Route - Exploring Drupal 8 Routing System (20)

introduction to Laravel and its Basic and origin
introduction to Laravel and its Basic and originintroduction to Laravel and its Basic and origin
introduction to Laravel and its Basic and origin
 
Memphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basicsMemphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basics
 
Final dependency presentation.odp
Final dependency presentation.odpFinal dependency presentation.odp
Final dependency presentation.odp
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
 
[Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
 [Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr... [Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
[Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
 
Laravel
LaravelLaravel
Laravel
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
 
Coder Presentation Szeged
Coder Presentation SzegedCoder Presentation Szeged
Coder Presentation Szeged
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8
[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8
[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8
 
Ruby on rails RAD
Ruby on rails RADRuby on rails RAD
Ruby on rails RAD
 
EdTechJoker Spring 2020 - Lecture 7 Drupal intro
EdTechJoker Spring 2020 - Lecture 7 Drupal introEdTechJoker Spring 2020 - Lecture 7 Drupal intro
EdTechJoker Spring 2020 - Lecture 7 Drupal intro
 
Semalt: 3 Steps To PHP Web Page Scraping Web
Semalt: 3 Steps To PHP Web Page Scraping WebSemalt: 3 Steps To PHP Web Page Scraping Web
Semalt: 3 Steps To PHP Web Page Scraping Web
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Pyramid tutorial
Pyramid tutorialPyramid tutorial
Pyramid tutorial
 
A deep dive into Drupal 8 routing
A deep dive into Drupal 8 routingA deep dive into Drupal 8 routing
A deep dive into Drupal 8 routing
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 

More from Srijan Technologies

[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
Srijan Technologies
 
[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...
[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...
[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...
Srijan Technologies
 
[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...
[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...
[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...
Srijan Technologies
 
[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage
[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage
[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage
Srijan Technologies
 
[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...
[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...
[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...
Srijan Technologies
 
[Srijan Wednesday Webinars] Is Your Business Ready for GDPR
[Srijan Wednesday Webinars] Is Your Business Ready for GDPR[Srijan Wednesday Webinars] Is Your Business Ready for GDPR
[Srijan Wednesday Webinars] Is Your Business Ready for GDPR
Srijan Technologies
 
[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business
[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business
[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business
Srijan Technologies
 
[Srijan Wednesday Webinars] How to Design a Chatbot that Works
[Srijan Wednesday Webinars] How to Design a Chatbot that Works[Srijan Wednesday Webinars] How to Design a Chatbot that Works
[Srijan Wednesday Webinars] How to Design a Chatbot that Works
Srijan Technologies
 
[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine
[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine
[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine
Srijan Technologies
 
[Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing
[Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing [Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing
[Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing
Srijan Technologies
 
[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System
[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System
[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System
Srijan Technologies
 
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
Srijan Technologies
 
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
Srijan Technologies
 
[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...
[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...
[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...
Srijan Technologies
 
[Srijan Wednesday Webinars] Building a High Performance QA Team
[Srijan Wednesday Webinars] Building a High Performance QA Team[Srijan Wednesday Webinars] Building a High Performance QA Team
[Srijan Wednesday Webinars] Building a High Performance QA Team
Srijan Technologies
 
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
Srijan Technologies
 
[Srijan Wednesday Webinars] Transitioning to an Organization-wide Agile Culture
[Srijan Wednesday Webinars] Transitioning to an Organization-wide Agile Culture[Srijan Wednesday Webinars] Transitioning to an Organization-wide Agile Culture
[Srijan Wednesday Webinars] Transitioning to an Organization-wide Agile Culture
Srijan Technologies
 
[Srijan Wednesday Webinars] Opportunities and Challenges in Enterprise UX Design
[Srijan Wednesday Webinars] Opportunities and Challenges in Enterprise UX Design[Srijan Wednesday Webinars] Opportunities and Challenges in Enterprise UX Design
[Srijan Wednesday Webinars] Opportunities and Challenges in Enterprise UX Design
Srijan Technologies
 
[Srijan Wednesday Webinars] Why Enterprises Should Embrace Distributed Agile ...
[Srijan Wednesday Webinars] Why Enterprises Should Embrace Distributed Agile ...[Srijan Wednesday Webinars] Why Enterprises Should Embrace Distributed Agile ...
[Srijan Wednesday Webinars] Why Enterprises Should Embrace Distributed Agile ...
Srijan Technologies
 
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
Srijan Technologies
 

More from Srijan Technologies (20)

[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
 
[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...
[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...
[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...
 
[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...
[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...
[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...
 
[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage
[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage
[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage
 
[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...
[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...
[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...
 
[Srijan Wednesday Webinars] Is Your Business Ready for GDPR
[Srijan Wednesday Webinars] Is Your Business Ready for GDPR[Srijan Wednesday Webinars] Is Your Business Ready for GDPR
[Srijan Wednesday Webinars] Is Your Business Ready for GDPR
 
[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business
[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business
[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business
 
[Srijan Wednesday Webinars] How to Design a Chatbot that Works
[Srijan Wednesday Webinars] How to Design a Chatbot that Works[Srijan Wednesday Webinars] How to Design a Chatbot that Works
[Srijan Wednesday Webinars] How to Design a Chatbot that Works
 
[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine
[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine
[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine
 
[Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing
[Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing [Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing
[Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing
 
[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System
[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System
[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System
 
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
 
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
 
[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...
[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...
[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...
 
[Srijan Wednesday Webinars] Building a High Performance QA Team
[Srijan Wednesday Webinars] Building a High Performance QA Team[Srijan Wednesday Webinars] Building a High Performance QA Team
[Srijan Wednesday Webinars] Building a High Performance QA Team
 
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
 
[Srijan Wednesday Webinars] Transitioning to an Organization-wide Agile Culture
[Srijan Wednesday Webinars] Transitioning to an Organization-wide Agile Culture[Srijan Wednesday Webinars] Transitioning to an Organization-wide Agile Culture
[Srijan Wednesday Webinars] Transitioning to an Organization-wide Agile Culture
 
[Srijan Wednesday Webinars] Opportunities and Challenges in Enterprise UX Design
[Srijan Wednesday Webinars] Opportunities and Challenges in Enterprise UX Design[Srijan Wednesday Webinars] Opportunities and Challenges in Enterprise UX Design
[Srijan Wednesday Webinars] Opportunities and Challenges in Enterprise UX Design
 
[Srijan Wednesday Webinars] Why Enterprises Should Embrace Distributed Agile ...
[Srijan Wednesday Webinars] Why Enterprises Should Embrace Distributed Agile ...[Srijan Wednesday Webinars] Why Enterprises Should Embrace Distributed Agile ...
[Srijan Wednesday Webinars] Why Enterprises Should Embrace Distributed Agile ...
 
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
 

Recently uploaded

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 

Recently uploaded (20)

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 

[Srijan Wednesday Webinars] Let’s Take the Best Route - Exploring Drupal 8 Routing System

  • 1. Exploring Drupal 8 Routing System Surbhi Sriwal | Drupal Developer, Srijan Technologies #SrijanWW | @srijan
  • 2. #SrijanWW | @srijan Surbhi Sriwal Drupal Developer at Srijan Technologies https://www.drupal.org/u/surbz @surbhisriwal Whoami
  • 3. #SrijanWW | @srijan Srijan | Global Open Source leaders 15 Years of profitable Growth 200+ Largest Drupal Company in Asia Pacific Region 45+ Certified Drupal Engineers 12 Multi-year Global Customers Asia’s Largest & Top 10 Worldwide
  • 4. #SrijanWW | @srijan Agenda What next? ● Overview - with an introductory example ● Underlying mechanism of routing - HTTP Kernel ● How is Drupal 8 routing different from tightly coupled Drupal 7 hook_menu() ● How Drupal 8 makes use of yml and controller ● Structure of Routes ● Precedence of same routes ● Simple access checks using permissions and roles ● Dynamic routes and using params in routes ● Some Code
  • 6. #SrijanWW | @srijan What is a Route in Drupal? In Drupal route is a way defined that would return some sort of content. Example: /node the default front page is a route. /node/add /node/{nid}/edit
  • 7. #SrijanWW | @srijan Routing In Symfony In Symfony we have #app/config/routing.yml blog_show: path: /blog defaults: {_controller: ControllerName:method}
  • 8. #SrijanWW | @srijan In Drupal 7 routing is handled by hook_menu(). Apart from just routing it had many other responsibilities to do ● Routing ● Access Control ● Visible Navigation In Drupal 7 we have menu_router table This table stores all the paths. As soon as the request comes - the path is fetched from this table and corresponding request is fetched. How is it different from Drupal 7?
  • 9. #SrijanWW | @srijan It’s too much for a single function to handle and made some sort of a tight coupling It looks a much of alien concept to developers coming from other MVC frameworks How is it different from Drupal 7?
  • 10. #SrijanWW | @srijan D8: Goodbye hook_menu()
  • 11. #SrijanWW | @srijan D8:The Underlying Mechanism Of Routing Drupal 8 has adopted its routing from Symfony. What happens when drupal receives a request - HTTP Kernel How Drupal does all this ?
  • 12. #SrijanWW | @srijan Symfony HTTP Kernel You can have a look in the Drupal code where this Symfony Kernel lies by going to <drupal folder>/vendor/symfony/http-kernel/
  • 13. #SrijanWW | @srijan Symfony HTTP Kernel Drupal System uses this HTTP Kernel which gets the request and asks other systems to produce o/p what are these other systems lets see
  • 14. #SrijanWW | @srijan Drupal 8 makes use of yml and controllers Drupal System uses this HTTP Kernel which gets the request and asks other systems to produce o/p These other systems are Routing File .routing.yml Controller
  • 15. #SrijanWW | @srijan <modulename>.routing.yml YML file tells Drupal how to behave when a particular path is encountered. If you want to specify a default value, you put it into the defaults array. In the same yml array you specify the class and method connected with '::' to tell the system where to look up stuff. YML Files
  • 16. #SrijanWW | @srijan ExampleController.php - Inside src/Controller/ Controller is a piece of code that is responsible to generate the response object. The key concept is the controller which gets some parameters from the system and converts them to the response. So everything without an underscore is considered to be a parameter to the controller. Every other property has nothing to do with the controller parameters and so are considered to be internal and so have an underscore as prefix. Controllers
  • 17. #SrijanWW | @srijan How exactly hook_menu() was decoupled?
  • 18. #SrijanWW | @srijan This was an introductory example now let's explore some more options along with routes so that we can play around a bit later. I have tried to cover the examples by referring Symfony docs along with Drupal docs and have tried to bring a combination altogether. Drupal can do a lot more than Symfony like access checks based on permissions and roles I have tried to cover that too, let’s see them one by one ... Structure Of Routes
  • 20. #SrijanWW | @srijan Whenever you have a {placeholder} in your route path, that portion becomes a wildcard: it matches any value. Your controller can now also have an argument called $placeholder (the wildcard and argument names must match). Dynamic routes - path is a required param it can have static or dynamic arguments Note that the first item of the path must not be dynamic To limit - {slug} can be restricted by defining requirements Dynamic Routes
  • 21. #SrijanWW | @srijan When two routes match the same URL, the first route that's loaded wins. Unfortunately, that means that /blog/test will match the blogshow and not eventshow. No good! To fix this, add a requirement was added. Precedence of same routes
  • 22. #SrijanWW | @srijan If you want to get access to an entity type you can use named params in the url.$user is the name of an entity type. If the userid does not exist drupal would give a 404. Named parameters are not sanitized by default.This means that you really should sanitize all values prior to use. You can somewhat decrease a code injection security concern by specifying regex requirements. Inside the controller you will have access to the the complete user object Named Params In Route
  • 23. #SrijanWW | @srijan Inside the controller you will have access to the the complete user object which can be used as per the logic. Named Params In Route
  • 24. #SrijanWW | @srijan You don't want to take care about loading an entity, see /user/{user} as example. For entities you basically just use the name of the entity type and it will execute a entity_load with the ID passed in the URL. Param converter manager Upcasting
  • 28. #SrijanWW | @srijan While working with routing If you update a routes file in Drupal 8 how do you clear the cache? So instead of clearing caches you can rebuild the router table If you use drush drush ev 'Drupal::service("router.builder")->rebuild();' to rebuild the routing information without clearing all the caches. If you use drupal console drupal router:rebuild Some Useful Commands
  • 29. #SrijanWW | @srijan https://github.com/surbz/routing You can checkout this code from github
  • 30. #SrijanWW | @srijan Conclusion 1 So the steps should be define a route name Attach a path / url to it Decide this url has to be static or dynamic If dynamic we might want to sanitize this value before it passes to controller this can be achieved by restricting the type of input like a regex At times we may not want all the users to access routes and may want to limit access We have seen how Symfony routing works using HTTP Kernel and how Drupal 8 makes use of it. We have seen Drupal can do more that what was available in Symfony.It can put access checks based on roles and permissions which is something very specific to Drupal itself. 3 2 Drupal 8 has decoupled the tight coupling we had with Drupal 74
  • 31. #SrijanWW | @srijan Know More Thank You @surbhisriwal www.srijan.net