SlideShare a Scribd company logo
1 of 17
DRUPAL 8 PLUGIN API
How to make your module extendable using plugins?
Manoj K
• Drupal Dev, Enthusiast, and Contributor
• Sr. Drupal Consultant @ Valuebound
• Speaker | Blogger | Mentor
• d.o/manojapare
• Github/manoj-apare
• @manojapare
INTRODUCTION
• Plugins
• Plugin API
PLUGINS vs. INFO HOOKS
WHEN TO USE?
• Plugin
• Service
PLUGIN SYSTEM: 3 BASE ELEMENTS
1.Plugin Types
2.Plugin Discovery
3.Plugin Factory
PLUGIN DISCOVERY TYPES
1. StaticDiscovery:
$this->discovery = new StaticDiscovery();
// Add a plugin with a custom value.
$this->discovery->setDefinition('test_block', [
'class' => 'Drupalplugin_testPluginplugin_testmock_blockMockTestBlock',
'metadata' => [
'custom' => TRUE,
],
]);
PLUGIN DISCOVERY TYPES
2. HookDiscovery:/
foreach ($this->moduleHandler->getImplementations($this->hook) as $module) {
$result = $this->moduleHandler->invoke($module, $this->hook);
foreach ($result as $plugin_id => $definition) {
$definition['provider'] = $module;
$definitions[$plugin_id] = $definition;
}
}
PLUGIN DISCOVERY TYPES
3. AnnotatedClassDiscovery:
@FieldType(
id = "datetime",
label = @Translation("Date"),
description = @Translation("Create and store date values."),
default_widget = "datetime_default",
default_formatter = "datetime_default",
list_class = "DrupaldatetimePluginFieldFieldTypeDateTimeFieldItemList",
constraints = {"DateTimeFormat" = {}}
)
PLUGIN DISCOVERY TYPES
4. YamlDiscovery:
$yaml_discovery = new YamlDiscovery(
'links.action',
$this->moduleHandler->getModuleDirectories()
);
CREATE PLUGIN MANAGER
Drupal Console commands:
• generate:plugin:type:annotation (gpta)
• generate:plugin:type:yaml (gpty)
CREATE PLUGIN MANAGER (Continued)
• DefaultPluginManager
• As a service:
services:
plugin.manager.archiver:
class: DrupalCoreArchiverArchiverManager
parent: default_plugin_manager
CREATE NEW PLUGIN
Drupal Console commands:
• debug:plugin (dpl)
• generate:plugin:skeleton (gps)
USING PLUGIN MANAGER
1.Invoke plugin class:
$type = Drupal::service('plugin.manager.archiver');
1.Get a list of available plugins:
$plugin_definitions = $type->getDefinitions();
1.Get a specific plugin:
$plugin_definition = $type->getDefinition('plugin_id');
1.Create an instance of a plugin:
$plugin = $type->createInstance('plugin_id', ['of' => 'configuration values']);
References
• https://www.drupal.org/docs/8/api/plugin-api
• http://drupalconsole.com/commands
Drupal 8 Plugin API - Manoj K
Drupal 8 Plugin API - Manoj K

More Related Content

Similar to Drupal 8 Plugin API - Manoj K

CQCON CQ Maven Methods
CQCON CQ Maven MethodsCQCON CQ Maven Methods
CQCON CQ Maven MethodsAndrew Savory
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Oscar Merida
 
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
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Jay Friendly
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet CampPuppet
 
Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016John Napiorkowski
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Drupalcon Paris
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 
Advanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareAdvanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareOpevel
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGapAlex S
 
Puppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachPuppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachAlessandro Franceschi
 
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...Puppet
 
Developing WordPress Plugins : For Begineers
Developing WordPress Plugins :  For BegineersDeveloping WordPress Plugins :  For Begineers
Developing WordPress Plugins : For BegineersM A Hossain Tonu
 
Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2Confiz
 

Similar to Drupal 8 Plugin API - Manoj K (20)

Dcp'15
Dcp'15Dcp'15
Dcp'15
 
CQ Maven Methods
CQ Maven MethodsCQ Maven Methods
CQ Maven Methods
 
CQCON CQ Maven Methods
CQCON CQ Maven MethodsCQCON CQ Maven Methods
CQCON CQ Maven Methods
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
 
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
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
 
Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016Catalyst patterns-yapc-eu-2016
Catalyst patterns-yapc-eu-2016
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
Advanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareAdvanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshare
 
Testing
TestingTesting
Testing
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGap
 
Angular js-crash-course
Angular js-crash-courseAngular js-crash-course
Angular js-crash-course
 
End_to_End_DevOps.pptx
End_to_End_DevOps.pptxEnd_to_End_DevOps.pptx
End_to_End_DevOps.pptx
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
Puppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachPuppet modules: An Holistic Approach
Puppet modules: An Holistic Approach
 
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
Puppet Modules: An Holistic Approach - Alessandro Franceschi of Lab42 - Puppe...
 
Developing WordPress Plugins : For Begineers
Developing WordPress Plugins :  For BegineersDeveloping WordPress Plugins :  For Begineers
Developing WordPress Plugins : For Begineers
 
Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2
 

More from DrupalMumbai

20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...DrupalMumbai
 
How To Write Dynamic Migrations - Mohit Aghera
How To Write Dynamic Migrations - Mohit AgheraHow To Write Dynamic Migrations - Mohit Aghera
How To Write Dynamic Migrations - Mohit AgheraDrupalMumbai
 
Event Schedule DCM2018 Event Schedule DCM2018 100% 10 Too Many Project Meth...
 Event Schedule DCM2018 Event Schedule DCM2018 100% 10  Too Many Project Meth... Event Schedule DCM2018 Event Schedule DCM2018 100% 10  Too Many Project Meth...
Event Schedule DCM2018 Event Schedule DCM2018 100% 10 Too Many Project Meth...DrupalMumbai
 
Being! Black Hat with Drupal - Anand Toshniwal
Being! Black Hat with Drupal - Anand ToshniwalBeing! Black Hat with Drupal - Anand Toshniwal
Being! Black Hat with Drupal - Anand ToshniwalDrupalMumbai
 
AMPifying your Drupal 8 Site : higher performance and higher engagement - Par...
AMPifying your Drupal 8 Site : higher performance and higher engagement - Par...AMPifying your Drupal 8 Site : higher performance and higher engagement - Par...
AMPifying your Drupal 8 Site : higher performance and higher engagement - Par...DrupalMumbai
 
Virtual Reality in WEB ! - Vidit Anjaria, Swastik Pareek
Virtual Reality in WEB ! - Vidit Anjaria,  Swastik PareekVirtual Reality in WEB ! - Vidit Anjaria,  Swastik Pareek
Virtual Reality in WEB ! - Vidit Anjaria, Swastik PareekDrupalMumbai
 
Building and Maintaining a Healthy Community - Jayesh Katta Ramalingaiah
Building and Maintaining a Healthy Community - Jayesh Katta RamalingaiahBuilding and Maintaining a Healthy Community - Jayesh Katta Ramalingaiah
Building and Maintaining a Healthy Community - Jayesh Katta RamalingaiahDrupalMumbai
 
How to use CSS Grids today in the real world - Manjit Singh
How to use CSS Grids today in the real world - Manjit SinghHow to use CSS Grids today in the real world - Manjit Singh
How to use CSS Grids today in the real world - Manjit SinghDrupalMumbai
 
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overviewDrupalMumbai
 
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Administration
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal AdministrationDrupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Administration
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal AdministrationDrupalMumbai
 
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Terminologies
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal TerminologiesDrupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Terminologies
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal TerminologiesDrupalMumbai
 
Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal
Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal
Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal DrupalMumbai
 
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Intro
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal IntroDrupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Intro
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal IntroDrupalMumbai
 
Drupal Mumbai Introduction
Drupal Mumbai IntroductionDrupal Mumbai Introduction
Drupal Mumbai IntroductionDrupalMumbai
 

More from DrupalMumbai (14)

20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
20 cool features that is in PHP 7, we missed in PHP 5. Let walkthrough with t...
 
How To Write Dynamic Migrations - Mohit Aghera
How To Write Dynamic Migrations - Mohit AgheraHow To Write Dynamic Migrations - Mohit Aghera
How To Write Dynamic Migrations - Mohit Aghera
 
Event Schedule DCM2018 Event Schedule DCM2018 100% 10 Too Many Project Meth...
 Event Schedule DCM2018 Event Schedule DCM2018 100% 10  Too Many Project Meth... Event Schedule DCM2018 Event Schedule DCM2018 100% 10  Too Many Project Meth...
Event Schedule DCM2018 Event Schedule DCM2018 100% 10 Too Many Project Meth...
 
Being! Black Hat with Drupal - Anand Toshniwal
Being! Black Hat with Drupal - Anand ToshniwalBeing! Black Hat with Drupal - Anand Toshniwal
Being! Black Hat with Drupal - Anand Toshniwal
 
AMPifying your Drupal 8 Site : higher performance and higher engagement - Par...
AMPifying your Drupal 8 Site : higher performance and higher engagement - Par...AMPifying your Drupal 8 Site : higher performance and higher engagement - Par...
AMPifying your Drupal 8 Site : higher performance and higher engagement - Par...
 
Virtual Reality in WEB ! - Vidit Anjaria, Swastik Pareek
Virtual Reality in WEB ! - Vidit Anjaria,  Swastik PareekVirtual Reality in WEB ! - Vidit Anjaria,  Swastik Pareek
Virtual Reality in WEB ! - Vidit Anjaria, Swastik Pareek
 
Building and Maintaining a Healthy Community - Jayesh Katta Ramalingaiah
Building and Maintaining a Healthy Community - Jayesh Katta RamalingaiahBuilding and Maintaining a Healthy Community - Jayesh Katta Ramalingaiah
Building and Maintaining a Healthy Community - Jayesh Katta Ramalingaiah
 
How to use CSS Grids today in the real world - Manjit Singh
How to use CSS Grids today in the real world - Manjit SinghHow to use CSS Grids today in the real world - Manjit Singh
How to use CSS Grids today in the real world - Manjit Singh
 
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
13th Sep - Drupal Global Training Day by TCS - Drupal core advanced overview
 
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Administration
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal AdministrationDrupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Administration
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Administration
 
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Terminologies
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal TerminologiesDrupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Terminologies
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Terminologies
 
Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal
Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal
Drupal Global Training Day by Drupal Mumbai 6th Sep - Extending Drupal
 
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Intro
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal IntroDrupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Intro
Drupal Global Training Day by Drupal Mumbai 6th Sep - Drupal Intro
 
Drupal Mumbai Introduction
Drupal Mumbai IntroductionDrupal Mumbai Introduction
Drupal Mumbai Introduction
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Recently uploaded (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Drupal 8 Plugin API - Manoj K

  • 1. DRUPAL 8 PLUGIN API How to make your module extendable using plugins?
  • 2. Manoj K • Drupal Dev, Enthusiast, and Contributor • Sr. Drupal Consultant @ Valuebound • Speaker | Blogger | Mentor • d.o/manojapare • Github/manoj-apare • @manojapare
  • 5. WHEN TO USE? • Plugin • Service
  • 6. PLUGIN SYSTEM: 3 BASE ELEMENTS 1.Plugin Types 2.Plugin Discovery 3.Plugin Factory
  • 7. PLUGIN DISCOVERY TYPES 1. StaticDiscovery: $this->discovery = new StaticDiscovery(); // Add a plugin with a custom value. $this->discovery->setDefinition('test_block', [ 'class' => 'Drupalplugin_testPluginplugin_testmock_blockMockTestBlock', 'metadata' => [ 'custom' => TRUE, ], ]);
  • 8. PLUGIN DISCOVERY TYPES 2. HookDiscovery:/ foreach ($this->moduleHandler->getImplementations($this->hook) as $module) { $result = $this->moduleHandler->invoke($module, $this->hook); foreach ($result as $plugin_id => $definition) { $definition['provider'] = $module; $definitions[$plugin_id] = $definition; } }
  • 9. PLUGIN DISCOVERY TYPES 3. AnnotatedClassDiscovery: @FieldType( id = "datetime", label = @Translation("Date"), description = @Translation("Create and store date values."), default_widget = "datetime_default", default_formatter = "datetime_default", list_class = "DrupaldatetimePluginFieldFieldTypeDateTimeFieldItemList", constraints = {"DateTimeFormat" = {}} )
  • 10. PLUGIN DISCOVERY TYPES 4. YamlDiscovery: $yaml_discovery = new YamlDiscovery( 'links.action', $this->moduleHandler->getModuleDirectories() );
  • 11. CREATE PLUGIN MANAGER Drupal Console commands: • generate:plugin:type:annotation (gpta) • generate:plugin:type:yaml (gpty)
  • 12. CREATE PLUGIN MANAGER (Continued) • DefaultPluginManager • As a service: services: plugin.manager.archiver: class: DrupalCoreArchiverArchiverManager parent: default_plugin_manager
  • 13. CREATE NEW PLUGIN Drupal Console commands: • debug:plugin (dpl) • generate:plugin:skeleton (gps)
  • 14. USING PLUGIN MANAGER 1.Invoke plugin class: $type = Drupal::service('plugin.manager.archiver'); 1.Get a list of available plugins: $plugin_definitions = $type->getDefinitions(); 1.Get a specific plugin: $plugin_definition = $type->getDefinition('plugin_id'); 1.Create an instance of a plugin: $plugin = $type->createInstance('plugin_id', ['of' => 'configuration values']);