SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Matthew Wrather
http://wrathercreative.com • @mwrather
Sponsored by Exaltation of Larks, Inc.
http://larks.la • @LarksLA
GLAD High Performance Drupal Meetup
Hosted by Filter Digital
June 18, 2013 • Culver City, CA
Views Style Plugins
A Crash Course in
Drupal Hooks
• In Drupal, you take advantage of hooks via
function naming conventions, not by
registering a function with a listener.
• mymodule_foo() implements hook_foo()
• module_invoke_all($hook[, $args])
Returns an array of return values from each
of the hook implementations.
Views Plugins
• Display Plugins
How is your view exposed to other parts
of Drupal? (e.g.,“Page” and “Block”).
• Style Plugins
How is the view displayed? (e.g., <ul>,
<table>)
• And many more
Documentation: http://bit.ly/10MCs3j
Four Steps to Plug In
• Implement hook_views_api()
• Implement hook_views_plugin()
• Extend the appropriate plugin class
• (optional) Theme output
Module Structure
hook_views_api()
hook_views_plugins()
• Describes plugins defined by the module.
• This hook should be placed in the file MODULENAME.views.inc
and it will be auto-loaded.
• MODULENAME.views.inc must be in the directory specified by
the 'path' key returned by MODULENAME_views_api(), or the
same directory as the .module file, if 'path' is unspecified.
• All plugin files need to be referenced in MODULENAME.info with
the files[] directive.
• http://bit.ly/11SfM35
So let’s recap…
• We’ve implemented hook_views_api() in the
MODULENAME.module file
• We put MODULENAME.views.inc either alongside the
MODULENAME.module file or else in the directory
defined in the path key in MODULENAME_views_api()
• We’ve implemented hook_views_plugins() in the
MODULENAME.views.inc file
• …and we still haven’t written the plugin.
class views_plugin_style
• Remember, this is referenced in the
MODULENAME.info file
• This is the actual implementation of the views style,
and controls the options, options form, theme
functions, and rendering of the view.
• N.B.: the file needs to be named the same as the class
it defines with the .inc extention
• http://bit.ly/15w64lo
template_preprocess_
HOOKNAME(&$vars)
• In Drupal, theme preprocess functions set up the variables
that will be rendered in a .tpl.php or template file.
• (Cf. theme_ functions, which output HTML without
template files.)
• The template_ prefix tells Drupal to execute this function
before any other preprocess functions.
• Preprocess functions are hookable, so your module or
theme can override them following the convention
MODULENAME_preprocess_HOOKNAME(&$vars)
THEMENAME_preprocess_HOOKNAME(&$vars)
TEMPLATE.tpl.php
• Contains the actual HTML.
• Shouldn’t contain logic beyond basic flow
control:
if (){…} and foreach (){…}
• That said, you gotta do wahtcha gotta do
to balance the readability of the template
with the larger goal of separating
the business logic from the presentation layer.
Design Decisions & Tradeoffs
• The structure of the Drupal andViews APIs enforces
certain good coding practices like separation of concerns.
• Code organization:What goes where?
(By convention, you put all theViews stuff in views/).
• Validating and Sanitizing user input is crucial, especially in a
module like this one, whose point is displaying data. But the
good news is you get a lot of that for free from Drupal.
• Departures from best practices may seem to increase code
readability in the short term, but you’re going to have to lie
in the bed you’ve made…better to do it “The Drupal Way.”
Questions?
Let me ask my friend Google.
Matthew Wrather • @mwrather • wrathercreative.com

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011You Don't Know Query - WordCamp Portland 2011
You Don't Know Query - WordCamp Portland 2011
 
Building Pluggable Web Applications using Django
Building Pluggable Web Applications using DjangoBuilding Pluggable Web Applications using Django
Building Pluggable Web Applications using Django
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
Creating Custom Drupal Modules
Creating Custom Drupal ModulesCreating Custom Drupal Modules
Creating Custom Drupal Modules
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
Making Django and NoSQL Play Nice
Making Django and NoSQL Play NiceMaking Django and NoSQL Play Nice
Making Django and NoSQL Play Nice
 
Rebrand WordPress Admin
Rebrand WordPress AdminRebrand WordPress Admin
Rebrand WordPress Admin
 
In-depth changes to Drupal 8 javascript
In-depth changes to Drupal 8 javascriptIn-depth changes to Drupal 8 javascript
In-depth changes to Drupal 8 javascript
 
Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics Presentation
 
Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New Angle
 
Working with the django admin
Working with the django admin Working with the django admin
Working with the django admin
 
Odoo - CMS performances optimization
Odoo - CMS performances optimizationOdoo - CMS performances optimization
Odoo - CMS performances optimization
 
Django
DjangoDjango
Django
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in Django
 
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React AppsIntroducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework
 
Drupal image gallery_workshop
Drupal image gallery_workshopDrupal image gallery_workshop
Drupal image gallery_workshop
 
Mini Curso de Django
Mini Curso de DjangoMini Curso de Django
Mini Curso de Django
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh My
 

Ähnlich wie Views Style Plugins

Drupal module development
Drupal module developmentDrupal module development
Drupal module development
Rachit Gupta
 
Theming tips and tricks
Theming tips and tricksTheming tips and tricks
Theming tips and tricks
aaroncouch
 
Drupal 8: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Theming
drubb
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
Lauren Roth
 

Ähnlich wie Views Style Plugins (20)

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
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
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)
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module development
 
Theming tips and tricks
Theming tips and tricksTheming tips and tricks
Theming tips and tricks
 
CodeIgniter & MVC
CodeIgniter & MVCCodeIgniter & MVC
CodeIgniter & MVC
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsDrupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First Steps
 
Advanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshareAdvanced moduledevelopment d6_slideshare
Advanced moduledevelopment d6_slideshare
 
Drupal 8: Theming
Drupal 8: ThemingDrupal 8: Theming
Drupal 8: Theming
 
Dn D Custom 1
Dn D Custom 1Dn D Custom 1
Dn D Custom 1
 
Dn D Custom 1
Dn D Custom 1Dn D Custom 1
Dn D Custom 1
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
 
Drupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating ModulesDrupal - Introduction to Drupal Creating Modules
Drupal - Introduction to Drupal Creating Modules
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Fapi
FapiFapi
Fapi
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)
 
Drupal8 corporate training in Hyderabad
Drupal8 corporate training in HyderabadDrupal8 corporate training in Hyderabad
Drupal8 corporate training in Hyderabad
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Kürzlich hochgeladen (20)

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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...
 
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...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Views Style Plugins

  • 1. Matthew Wrather http://wrathercreative.com • @mwrather Sponsored by Exaltation of Larks, Inc. http://larks.la • @LarksLA GLAD High Performance Drupal Meetup Hosted by Filter Digital June 18, 2013 • Culver City, CA Views Style Plugins
  • 2. A Crash Course in Drupal Hooks • In Drupal, you take advantage of hooks via function naming conventions, not by registering a function with a listener. • mymodule_foo() implements hook_foo() • module_invoke_all($hook[, $args]) Returns an array of return values from each of the hook implementations.
  • 3. Views Plugins • Display Plugins How is your view exposed to other parts of Drupal? (e.g.,“Page” and “Block”). • Style Plugins How is the view displayed? (e.g., <ul>, <table>) • And many more Documentation: http://bit.ly/10MCs3j
  • 4.
  • 5. Four Steps to Plug In • Implement hook_views_api() • Implement hook_views_plugin() • Extend the appropriate plugin class • (optional) Theme output
  • 8. hook_views_plugins() • Describes plugins defined by the module. • This hook should be placed in the file MODULENAME.views.inc and it will be auto-loaded. • MODULENAME.views.inc must be in the directory specified by the 'path' key returned by MODULENAME_views_api(), or the same directory as the .module file, if 'path' is unspecified. • All plugin files need to be referenced in MODULENAME.info with the files[] directive. • http://bit.ly/11SfM35
  • 9.
  • 10.
  • 11. So let’s recap… • We’ve implemented hook_views_api() in the MODULENAME.module file • We put MODULENAME.views.inc either alongside the MODULENAME.module file or else in the directory defined in the path key in MODULENAME_views_api() • We’ve implemented hook_views_plugins() in the MODULENAME.views.inc file • …and we still haven’t written the plugin.
  • 12. class views_plugin_style • Remember, this is referenced in the MODULENAME.info file • This is the actual implementation of the views style, and controls the options, options form, theme functions, and rendering of the view. • N.B.: the file needs to be named the same as the class it defines with the .inc extention • http://bit.ly/15w64lo
  • 13.
  • 14.
  • 15. template_preprocess_ HOOKNAME(&$vars) • In Drupal, theme preprocess functions set up the variables that will be rendered in a .tpl.php or template file. • (Cf. theme_ functions, which output HTML without template files.) • The template_ prefix tells Drupal to execute this function before any other preprocess functions. • Preprocess functions are hookable, so your module or theme can override them following the convention MODULENAME_preprocess_HOOKNAME(&$vars) THEMENAME_preprocess_HOOKNAME(&$vars)
  • 16. TEMPLATE.tpl.php • Contains the actual HTML. • Shouldn’t contain logic beyond basic flow control: if (){…} and foreach (){…} • That said, you gotta do wahtcha gotta do to balance the readability of the template with the larger goal of separating the business logic from the presentation layer.
  • 17. Design Decisions & Tradeoffs • The structure of the Drupal andViews APIs enforces certain good coding practices like separation of concerns. • Code organization:What goes where? (By convention, you put all theViews stuff in views/). • Validating and Sanitizing user input is crucial, especially in a module like this one, whose point is displaying data. But the good news is you get a lot of that for free from Drupal. • Departures from best practices may seem to increase code readability in the short term, but you’re going to have to lie in the bed you’ve made…better to do it “The Drupal Way.”
  • 18. Questions? Let me ask my friend Google. Matthew Wrather • @mwrather • wrathercreative.com