SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
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

Más contenido relacionado

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

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 basicsJoe Ferguson
 
Final dependency presentation.odp
Final dependency presentation.odpFinal dependency presentation.odp
Final dependency presentation.odpSrijan Technologies
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
[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_menuSrijan 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 & CucumberUdaya Kiran
 
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 2008Mir 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 8Srijan 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 introBryan 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 Webilovemyindia18
 
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 routingNaveen Valecha
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQLRodrigo Prates
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorialsunniboy
 

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

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
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorial
 

Más de 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 SignageSrijan 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 GDPRSrijan 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 BusinessSrijan 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 WorksSrijan 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 EngineSrijan 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 SystemSrijan 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 DrupalSrijan 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 TeamSrijan 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 AppiumSrijan 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 CultureSrijan 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 DesignSrijan 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 AppSrijan Technologies
 

Más de 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
 

Último

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Último (20)

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

[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