SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
Overwriting code in Drupal
Vasile CHINDRIS
vasi1186 d.o
Why to overwrite?
● There is no “magic” solution that solves all our problems.
● We are not happy with the existing implementation.
● Wrap the current implementation.
● ... plenty other reasons.
● Good frameworks should (easily) allow overwriting the code.
without touching the core!
What to overwrite?
● Classes.
● Functions (possible in a few cases in Drupal).
● Every piece of the framework (ideal case).
and again, without touching the core!
Overwriting menu items: D7
hook_menu_alter(&$items)
Overwriting menu items: D8
● There is no hook_menu_alter() in D8.
● We have to alter the routes defined in the routing.yml file.
● We use an EventSubscriber.
The event subscriber is declared in the utils.services.yml file
In libDrupalutilsControllerCustomNodeController.php:
Overwriting menu items: real use case
We have a hook_menu():
When using a file that is uploaded with ajax.
Why?
Overwrite existing hooks: D7
hook_module_implements_alter(&$implementations, $hook)
Use case: remove the hook_user_view() from the user module.
A real use case
You have a module called “action” on your site.
Overwriting existing hooks: D8
● Good news: the same as in D7!
● hook_module_implements_alter() exists also in D8
Overwrite views plugins: D7
● It is a PHP class: views_plugin_pager_full
● Extend the class: class A extends B
● Views full pager plugin.
● hook_views_plugins()
● hook_views_plugins_alter()
How is the B class instantiated in the current implementation?
Overwrite views handlers: D7
● How are they created?
● The same as plugins are, in _views_create_handler()
● hook_views_handlers_alter()
● Ooops: there is no hook_views_handlers_alter()
● Make it the hard way: alter the file registry.
● hook_registry_files_alter()
Add to the custom.info file:
Copy the entire code from the original file to the new file.
Big issue: we are not extending, but cloning core!
Put the original class into a new file and change only the name
of the class
Add the file to the files array in the .info file:
Extend the “new” original class:
● What happens when the module updates?
● Manually update the class.
● Goal 99% achieved: did not change any implementation,
only the class name.
● Can be used with any classes in D7.
Overwrite views plugins: D8
● How are they constructed?
● A bit different than D7.
● But, we have the hook_views_plugins_pager_alter()
● There is an alter hook for every plugin:
hook_views_plugin_pluginname_alter()
Overwrite views handlers: D8
● Same issue as in D7, no alter hook.
● Still to find a way to overwrite them, cannot apply the
same solution as in D7.
● One alternate solution: hook_views_data_alter().
● The handler class name is stored in the
cache_views_info table.
Conclusions
● Evaluate first the code you want to overwrite.
● Many things in Drupal can be overwritten with alter hooks.
● When extending classes, if possible do not do it the “hard
way”.
Overwriting code in Drupal
Thank you!
Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

AngularDart Introduction
AngularDart IntroductionAngularDart Introduction
AngularDart IntroductionNikolaus Graf
 
27 - Panorama Necto 14 component mode & java script - visualization & data di...
27 - Panorama Necto 14 component mode & java script - visualization & data di...27 - Panorama Necto 14 component mode & java script - visualization & data di...
27 - Panorama Necto 14 component mode & java script - visualization & data di...Panorama Software
 
React.js触ってみた 吉澤和香奈
React.js触ってみた 吉澤和香奈React.js触ってみた 吉澤和香奈
React.js触ってみた 吉澤和香奈Wakana Yoshizawa
 
jQuery basics
jQuery basicsjQuery basics
jQuery basicsKamal S
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeMark Meyer
 
Modern wx perl
Modern wx perlModern wx perl
Modern wx perllichtkind
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with ReduxVedran Blaženka
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max PetruckMaksym Petruk
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and reduxCuong Ho
 
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
9\9 SSIS 2008R2_Training - Package Reliability and Package ExecutionPramod Singla
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and ReduxGlib Kechyn
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 
React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15Rob Gietema
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play NiceAlex Gaynor
 

Was ist angesagt? (20)

Svelte JS introduction
Svelte JS introductionSvelte JS introduction
Svelte JS introduction
 
JavaScript Operators
JavaScript OperatorsJavaScript Operators
JavaScript Operators
 
AngularDart Introduction
AngularDart IntroductionAngularDart Introduction
AngularDart Introduction
 
27 - Panorama Necto 14 component mode & java script - visualization & data di...
27 - Panorama Necto 14 component mode & java script - visualization & data di...27 - Panorama Necto 14 component mode & java script - visualization & data di...
27 - Panorama Necto 14 component mode & java script - visualization & data di...
 
React.js触ってみた 吉澤和香奈
React.js触ってみた 吉澤和香奈React.js触ってみた 吉澤和香奈
React.js触ってみた 吉澤和香奈
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers Make
 
Modern wx perl
Modern wx perlModern wx perl
Modern wx perl
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
Lesson 07
Lesson 07Lesson 07
Lesson 07
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and redux
 
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
9\9 SSIS 2008R2_Training - Package Reliability and Package Execution
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
 
React outbox
React outboxReact outbox
React outbox
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
A brief guide to android gradle
A brief guide to android gradleA brief guide to android gradle
A brief guide to android gradle
 
React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play Nice
 
Dive into AngularJS and directives
Dive into AngularJS and directivesDive into AngularJS and directives
Dive into AngularJS and directives
 

Andere mochten auch

Web Expresso: Drupal 8 - What's new
Web Expresso: Drupal 8 - What's newWeb Expresso: Drupal 8 - What's new
Web Expresso: Drupal 8 - What's newAmazee Labs
 
Drupal High Availability and High Performance
Drupal High Availability and High PerformanceDrupal High Availability and High Performance
Drupal High Availability and High PerformanceAmazee Labs
 
Strategy Session (DrupalCamp CO)
Strategy Session (DrupalCamp CO)Strategy Session (DrupalCamp CO)
Strategy Session (DrupalCamp CO)Amazee Labs
 
My Job Is Harder Than Yours (D4D Boston 2014)
My Job Is Harder Than Yours (D4D Boston 2014)My Job Is Harder Than Yours (D4D Boston 2014)
My Job Is Harder Than Yours (D4D Boston 2014)Amazee Labs
 
Social Media & Community MGMT (for Startups)
Social Media & Community MGMT (for Startups)Social Media & Community MGMT (for Startups)
Social Media & Community MGMT (for Startups)Amazee Labs
 
PHP High Availability High Performance
PHP High Availability High PerformancePHP High Availability High Performance
PHP High Availability High PerformanceAmazee Labs
 
Logging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & KibanaLogging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & KibanaAmazee Labs
 

Andere mochten auch (7)

Web Expresso: Drupal 8 - What's new
Web Expresso: Drupal 8 - What's newWeb Expresso: Drupal 8 - What's new
Web Expresso: Drupal 8 - What's new
 
Drupal High Availability and High Performance
Drupal High Availability and High PerformanceDrupal High Availability and High Performance
Drupal High Availability and High Performance
 
Strategy Session (DrupalCamp CO)
Strategy Session (DrupalCamp CO)Strategy Session (DrupalCamp CO)
Strategy Session (DrupalCamp CO)
 
My Job Is Harder Than Yours (D4D Boston 2014)
My Job Is Harder Than Yours (D4D Boston 2014)My Job Is Harder Than Yours (D4D Boston 2014)
My Job Is Harder Than Yours (D4D Boston 2014)
 
Social Media & Community MGMT (for Startups)
Social Media & Community MGMT (for Startups)Social Media & Community MGMT (for Startups)
Social Media & Community MGMT (for Startups)
 
PHP High Availability High Performance
PHP High Availability High PerformancePHP High Availability High Performance
PHP High Availability High Performance
 
Logging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & KibanaLogging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & Kibana
 

Ähnlich wie Overwriting code in Drupal

Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend developmentsparkfabrik
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DrupalDay
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentsparkfabrik
 
Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Anne Tomasevich
 
How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?DrupalGeeks
 
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...Eric Sembrat
 
Django tutorial
Django tutorialDjango tutorial
Django tutorialKsd Che
 
Drupal 6 to Drupal 8 Migration
Drupal 6 to Drupal 8 MigrationDrupal 6 to Drupal 8 Migration
Drupal 6 to Drupal 8 MigrationAmeex Technologies
 
Drupal 8 introduction to theming
Drupal 8  introduction to themingDrupal 8  introduction to theming
Drupal 8 introduction to themingBrahampal Singh
 
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)Konstantin Komelin
 
Drupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutionsDrupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutionsphp2ranjan
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - LondonMarek Sotak
 
Presentation drupalaton august 2013
Presentation drupalaton august 2013Presentation drupalaton august 2013
Presentation drupalaton august 2013Bram Goffings
 

Ähnlich wie Overwriting code in Drupal (20)

Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend development
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
 
Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8Building a Custom Theme in Drupal 8
Building a Custom Theme in Drupal 8
 
Hacking core
Hacking coreHacking core
Hacking core
 
D7 as D8
D7 as D8D7 as D8
D7 as D8
 
How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?How to Migrate Drupal 6 to Drupal 8?
How to Migrate Drupal 6 to Drupal 8?
 
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
Drupal 6 to Drupal 8 Migration
Drupal 6 to Drupal 8 MigrationDrupal 6 to Drupal 8 Migration
Drupal 6 to Drupal 8 Migration
 
Paragraphs at drupal 8.
Paragraphs at drupal 8.Paragraphs at drupal 8.
Paragraphs at drupal 8.
 
Drupal 8 introduction to theming
Drupal 8  introduction to themingDrupal 8  introduction to theming
Drupal 8 introduction to theming
 
Data herding
Data herdingData herding
Data herding
 
Data herding
Data herdingData herding
Data herding
 
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
#D8CX: Upgrade your modules to Drupal 8 (Part 1 and 2)
 
#D8 cx: upgrade your modules to drupal 8
#D8 cx: upgrade your modules to drupal 8 #D8 cx: upgrade your modules to drupal 8
#D8 cx: upgrade your modules to drupal 8
 
Drupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutionsDrupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutions
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - London
 
Presentation drupalaton august 2013
Presentation drupalaton august 2013Presentation drupalaton august 2013
Presentation drupalaton august 2013
 

Mehr von Amazee Labs

Marketingtag17 - Master Class "Digital Survival Guide"
Marketingtag17 - Master Class "Digital Survival Guide"Marketingtag17 - Master Class "Digital Survival Guide"
Marketingtag17 - Master Class "Digital Survival Guide"Amazee Labs
 
WebExpresso Agiles Projektmanagement 03/03/2016
WebExpresso Agiles Projektmanagement 03/03/2016WebExpresso Agiles Projektmanagement 03/03/2016
WebExpresso Agiles Projektmanagement 03/03/2016Amazee Labs
 
Drupal 8 deeper dive
Drupal 8 deeper diveDrupal 8 deeper dive
Drupal 8 deeper diveAmazee Labs
 
How to run a successful Drupal shop
How to run a successful Drupal shopHow to run a successful Drupal shop
How to run a successful Drupal shopAmazee Labs
 
Messbarkeit seo performance
Messbarkeit seo performance Messbarkeit seo performance
Messbarkeit seo performance Amazee Labs
 
Drupalcamp London 2015
Drupalcamp London 2015Drupalcamp London 2015
Drupalcamp London 2015Amazee Labs
 
Sonova.com building multilingual and multidomain drupal website
Sonova.com building multilingual and multidomain drupal websiteSonova.com building multilingual and multidomain drupal website
Sonova.com building multilingual and multidomain drupal websiteAmazee Labs
 
WebExpresso - Switch the Switch
WebExpresso - Switch the SwitchWebExpresso - Switch the Switch
WebExpresso - Switch the SwitchAmazee Labs
 
Amazee web expresso 2 2014
Amazee web expresso 2 2014Amazee web expresso 2 2014
Amazee web expresso 2 2014Amazee Labs
 
Web express-drupal-8
Web express-drupal-8Web express-drupal-8
Web express-drupal-8Amazee Labs
 
Manage and Deploy your sites with Drush
Manage and Deploy your sites with DrushManage and Deploy your sites with Drush
Manage and Deploy your sites with DrushAmazee Labs
 
There are no bad clients, just bad project managers
There are no bad clients, just bad project managersThere are no bad clients, just bad project managers
There are no bad clients, just bad project managersAmazee Labs
 
Translation Management
Translation ManagementTranslation Management
Translation ManagementAmazee Labs
 
Drupal High Availability High Performance 2012
Drupal High Availability High Performance 2012Drupal High Availability High Performance 2012
Drupal High Availability High Performance 2012Amazee Labs
 
Drupal für Entwickler
Drupal für EntwicklerDrupal für Entwickler
Drupal für EntwicklerAmazee Labs
 
Responsive Web Design - Ein Überblick
Responsive Web Design - Ein ÜberblickResponsive Web Design - Ein Überblick
Responsive Web Design - Ein ÜberblickAmazee Labs
 
Drupal & Wordpress
Drupal & WordpressDrupal & Wordpress
Drupal & WordpressAmazee Labs
 
Drupal 7 Einblick und Ausblick
Drupal 7 Einblick und AusblickDrupal 7 Einblick und Ausblick
Drupal 7 Einblick und AusblickAmazee Labs
 

Mehr von Amazee Labs (18)

Marketingtag17 - Master Class "Digital Survival Guide"
Marketingtag17 - Master Class "Digital Survival Guide"Marketingtag17 - Master Class "Digital Survival Guide"
Marketingtag17 - Master Class "Digital Survival Guide"
 
WebExpresso Agiles Projektmanagement 03/03/2016
WebExpresso Agiles Projektmanagement 03/03/2016WebExpresso Agiles Projektmanagement 03/03/2016
WebExpresso Agiles Projektmanagement 03/03/2016
 
Drupal 8 deeper dive
Drupal 8 deeper diveDrupal 8 deeper dive
Drupal 8 deeper dive
 
How to run a successful Drupal shop
How to run a successful Drupal shopHow to run a successful Drupal shop
How to run a successful Drupal shop
 
Messbarkeit seo performance
Messbarkeit seo performance Messbarkeit seo performance
Messbarkeit seo performance
 
Drupalcamp London 2015
Drupalcamp London 2015Drupalcamp London 2015
Drupalcamp London 2015
 
Sonova.com building multilingual and multidomain drupal website
Sonova.com building multilingual and multidomain drupal websiteSonova.com building multilingual and multidomain drupal website
Sonova.com building multilingual and multidomain drupal website
 
WebExpresso - Switch the Switch
WebExpresso - Switch the SwitchWebExpresso - Switch the Switch
WebExpresso - Switch the Switch
 
Amazee web expresso 2 2014
Amazee web expresso 2 2014Amazee web expresso 2 2014
Amazee web expresso 2 2014
 
Web express-drupal-8
Web express-drupal-8Web express-drupal-8
Web express-drupal-8
 
Manage and Deploy your sites with Drush
Manage and Deploy your sites with DrushManage and Deploy your sites with Drush
Manage and Deploy your sites with Drush
 
There are no bad clients, just bad project managers
There are no bad clients, just bad project managersThere are no bad clients, just bad project managers
There are no bad clients, just bad project managers
 
Translation Management
Translation ManagementTranslation Management
Translation Management
 
Drupal High Availability High Performance 2012
Drupal High Availability High Performance 2012Drupal High Availability High Performance 2012
Drupal High Availability High Performance 2012
 
Drupal für Entwickler
Drupal für EntwicklerDrupal für Entwickler
Drupal für Entwickler
 
Responsive Web Design - Ein Überblick
Responsive Web Design - Ein ÜberblickResponsive Web Design - Ein Überblick
Responsive Web Design - Ein Überblick
 
Drupal & Wordpress
Drupal & WordpressDrupal & Wordpress
Drupal & Wordpress
 
Drupal 7 Einblick und Ausblick
Drupal 7 Einblick und AusblickDrupal 7 Einblick und Ausblick
Drupal 7 Einblick und Ausblick
 

Kürzlich hochgeladen

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Kürzlich hochgeladen (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Overwriting code in Drupal

  • 1. Overwriting code in Drupal Vasile CHINDRIS vasi1186 d.o
  • 2. Why to overwrite? ● There is no “magic” solution that solves all our problems. ● We are not happy with the existing implementation. ● Wrap the current implementation. ● ... plenty other reasons. ● Good frameworks should (easily) allow overwriting the code. without touching the core!
  • 3. What to overwrite? ● Classes. ● Functions (possible in a few cases in Drupal). ● Every piece of the framework (ideal case). and again, without touching the core!
  • 4. Overwriting menu items: D7 hook_menu_alter(&$items)
  • 5.
  • 6.
  • 7. Overwriting menu items: D8 ● There is no hook_menu_alter() in D8. ● We have to alter the routes defined in the routing.yml file. ● We use an EventSubscriber.
  • 8. The event subscriber is declared in the utils.services.yml file
  • 9.
  • 11.
  • 12. Overwriting menu items: real use case We have a hook_menu():
  • 13. When using a file that is uploaded with ajax. Why?
  • 14.
  • 15. Overwrite existing hooks: D7 hook_module_implements_alter(&$implementations, $hook)
  • 16. Use case: remove the hook_user_view() from the user module.
  • 17.
  • 18.
  • 19. A real use case You have a module called “action” on your site.
  • 20.
  • 21. Overwriting existing hooks: D8 ● Good news: the same as in D7! ● hook_module_implements_alter() exists also in D8
  • 22. Overwrite views plugins: D7 ● It is a PHP class: views_plugin_pager_full ● Extend the class: class A extends B ● Views full pager plugin.
  • 23. ● hook_views_plugins() ● hook_views_plugins_alter() How is the B class instantiated in the current implementation?
  • 24.
  • 25. Overwrite views handlers: D7 ● How are they created? ● The same as plugins are, in _views_create_handler()
  • 26. ● hook_views_handlers_alter() ● Ooops: there is no hook_views_handlers_alter() ● Make it the hard way: alter the file registry. ● hook_registry_files_alter()
  • 27. Add to the custom.info file: Copy the entire code from the original file to the new file. Big issue: we are not extending, but cloning core!
  • 28. Put the original class into a new file and change only the name of the class Add the file to the files array in the .info file: Extend the “new” original class:
  • 29. ● What happens when the module updates? ● Manually update the class. ● Goal 99% achieved: did not change any implementation, only the class name. ● Can be used with any classes in D7.
  • 30. Overwrite views plugins: D8 ● How are they constructed? ● A bit different than D7. ● But, we have the hook_views_plugins_pager_alter() ● There is an alter hook for every plugin: hook_views_plugin_pluginname_alter()
  • 31. Overwrite views handlers: D8 ● Same issue as in D7, no alter hook. ● Still to find a way to overwrite them, cannot apply the same solution as in D7. ● One alternate solution: hook_views_data_alter(). ● The handler class name is stored in the cache_views_info table.
  • 32. Conclusions ● Evaluate first the code you want to overwrite. ● Many things in Drupal can be overwritten with alter hooks. ● When extending classes, if possible do not do it the “hard way”.
  • 33. Overwriting code in Drupal Thank you! Questions?