SlideShare a Scribd company logo
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?

More Related Content

What's hot

Svelte JS introduction
Svelte JS introductionSvelte JS introduction
Svelte JS introduction
Mikhail Kuznetcov
 
JavaScript Operators
JavaScript OperatorsJavaScript Operators
JavaScript Operators
Dr. Jasmine Beulah Gnanadurai
 
AngularDart Introduction
AngularDart IntroductionAngularDart Introduction
AngularDart Introduction
Nikolaus 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 basics
Kamal S
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers Make
Mark Meyer
 
Modern wx perl
Modern wx perlModern wx perl
Modern wx perl
lichtkind
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
Vedran Blaženka
 
Lesson 07
Lesson 07Lesson 07
Lesson 07
Gene Babon
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
Maksym Petruk
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and redux
Cuong 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 Execution
Pramod Singla
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
Glib Kechyn
 
React outbox
React outboxReact outbox
React outbox
Angela Lehru
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
A brief guide to android gradle
A brief guide to android gradleA brief guide to android gradle
A brief guide to android gradle
Leonardo YongUk Kim
 
React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15React Native: JS MVC Meetup #15
React Native: JS MVC Meetup #15
Rob Gietema
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play Nice
Alex Gaynor
 
Dive into AngularJS and directives
Dive into AngularJS and directivesDive into AngularJS and directives
Dive into AngularJS and directives
Tricode (part of Dept)
 

What's hot (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
 

Viewers also liked

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
Amazee Labs
 
Drupal High Availability and High Performance
Drupal High Availability and High PerformanceDrupal High Availability and High Performance
Drupal High Availability and High Performance
Amazee 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 Performance
Amazee Labs
 
Logging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & KibanaLogging with Elasticsearch, Logstash & Kibana
Logging with Elasticsearch, Logstash & Kibana
Amazee Labs
 

Viewers also liked (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
 

Similar to Overwriting code in Drupal

Drupal 8: frontend development
Drupal 8: frontend developmentDrupal 8: frontend development
Drupal 8: frontend development
sparkfabrik
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
Shabir Ahmad
 
DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8DDAY2014 - Features per Drupal 8
DDAY2014 - Features per Drupal 8
DrupalDay
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
sparkfabrik
 
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
Anne Tomasevich
 
Hacking core
Hacking coreHacking core
Hacking core
Ashok Modi
 
D7 as D8
D7 as D8D7 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?
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 tutorial
Ksd Che
 
Drupal 6 to Drupal 8 Migration
Drupal 6 to Drupal 8 MigrationDrupal 6 to Drupal 8 Migration
Drupal 6 to Drupal 8 Migration
Ameex Technologies
 
Paragraphs at drupal 8.
Paragraphs at drupal 8.Paragraphs at drupal 8.
Paragraphs at drupal 8.
Anatoliy Polyakov
 
Drupal 8 introduction to theming
Drupal 8  introduction to themingDrupal 8  introduction to theming
Drupal 8 introduction to theming
Brahampal Singh
 
Data herding
Data herdingData herding
Data herding
unbracketed
 
Data herding
Data herdingData herding
Data herding
unbracketed
 
#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
 
#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
DrupalCamp Kyiv Рысь
 
Drupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutionsDrupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutions
php2ranjan
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - London
Marek Sotak
 
Presentation drupalaton, August 2013
Presentation drupalaton, August 2013Presentation drupalaton, August 2013
Presentation drupalaton, August 2013
Nascom
 

Similar to 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
 

More from 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/2016
Amazee Labs
 
Drupal 8 deeper dive
Drupal 8 deeper diveDrupal 8 deeper dive
Drupal 8 deeper dive
Amazee 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 shop
Amazee 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 2015
Amazee 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 website
Amazee Labs
 
WebExpresso - Switch the Switch
WebExpresso - Switch the SwitchWebExpresso - Switch the Switch
WebExpresso - Switch the Switch
Amazee 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-8
Amazee 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 Drush
Amazee 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 managers
Amazee Labs
 
Translation Management
Translation ManagementTranslation Management
Translation Management
Amazee Labs
 
Drupal High Availability High Performance 2012
Drupal High Availability High Performance 2012Drupal High Availability High Performance 2012
Drupal High Availability High Performance 2012
Amazee Labs
 
Drupal für Entwickler
Drupal für EntwicklerDrupal für Entwickler
Drupal für Entwickler
Amazee Labs
 
Responsive Web Design - Ein Überblick
Responsive Web Design - Ein ÜberblickResponsive Web Design - Ein Überblick
Responsive Web Design - Ein Überblick
Amazee Labs
 
Drupal & Wordpress
Drupal & WordpressDrupal & Wordpress
Drupal & Wordpress
Amazee Labs
 
Drupal 7 Einblick und Ausblick
Drupal 7 Einblick und AusblickDrupal 7 Einblick und Ausblick
Drupal 7 Einblick und Ausblick
Amazee Labs
 

More from 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
 

Recently uploaded

The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 

Recently uploaded (20)

The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 

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?