SlideShare a Scribd company logo
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
Views Style Plugins
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
Views Style Plugins
Views Style Plugins
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
Views Style Plugins
Views Style Plugins
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

More Related Content

PDF
A Gentle Introduction to Drupal's Views API
PDF
I use drupal / 我是 OO 師,我用 Drupal
PDF
The Best (and Worst) of Django
PDF
Django Introduction & Tutorial
PDF
Drupal 8 版型開發變革
ODP
Introduction to Django
PDF
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
PDF
Django Overview
A Gentle Introduction to Drupal's Views API
I use drupal / 我是 OO 師,我用 Drupal
The Best (and Worst) of Django
Django Introduction & Tutorial
Drupal 8 版型開發變革
Introduction to Django
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
Django Overview

What's hot (20)

PDF
You Don't Know Query - WordCamp Portland 2011
PDF
Building Pluggable Web Applications using Django
PDF
Drupal Module Development
PPT
Creating Custom Drupal Modules
ODP
Django tech-talk
KEY
Making Django and NoSQL Play Nice
PPTX
Rebrand WordPress Admin
PDF
In-depth changes to Drupal 8 javascript
PPTX
Web development with django - Basics Presentation
PDF
Lone StarPHP 2013 - Building Web Apps from a New Angle
PDF
Working with the django admin
PDF
Odoo - CMS performances optimization
PPT
Django
PPTX
An Overview of Models in Django
PPTX
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
PDF
Djangocon 2014 angular + django
PDF
Introduction to Zend framework
PPT
Drupal image gallery_workshop
PDF
Mini Curso de Django
KEY
Overlays, Accordions & Tabs, Oh My
You Don't Know Query - WordCamp Portland 2011
Building Pluggable Web Applications using Django
Drupal Module Development
Creating Custom Drupal Modules
Django tech-talk
Making Django and NoSQL Play Nice
Rebrand WordPress Admin
In-depth changes to Drupal 8 javascript
Web development with django - Basics Presentation
Lone StarPHP 2013 - Building Web Apps from a New Angle
Working with the django admin
Odoo - CMS performances optimization
Django
An Overview of Models in Django
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
Djangocon 2014 angular + django
Introduction to Zend framework
Drupal image gallery_workshop
Mini Curso de Django
Overlays, Accordions & Tabs, Oh My
Ad

Similar to Views Style Plugins (20)

PDF
13th Sep, Drupal 7 advanced training by TCS
ODP
Drupal Best Practices
PDF
Staying Sane with Drupal (A Develper's Survival Guide)
PDF
Staying Sane with Drupal NEPHP
PPTX
Drupal module development
ODP
Theming tips and tricks
PPTX
CodeIgniter & MVC
PDF
Drupal 8 - Core and API Changes
PPTX
Drupal Camp Porto - Developing with Drupal: First Steps
PDF
Advanced moduledevelopment d6_slideshare
PDF
Drupal 8: Theming
PPT
Dn D Custom 1
PPT
Dn D Custom 1
PDF
Introduction To Drupal
PPT
Drupal - Introduction to Drupal Creating Modules
KEY
Introduction Django
KEY
PPT
Drupal Javascript for developers
PDF
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)
PPTX
Drupal8 corporate training in Hyderabad
13th Sep, Drupal 7 advanced training by TCS
Drupal Best Practices
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal NEPHP
Drupal module development
Theming tips and tricks
CodeIgniter & MVC
Drupal 8 - Core and API Changes
Drupal Camp Porto - Developing with Drupal: First Steps
Advanced moduledevelopment d6_slideshare
Drupal 8: Theming
Dn D Custom 1
Dn D Custom 1
Introduction To Drupal
Drupal - Introduction to Drupal Creating Modules
Introduction Django
Drupal Javascript for developers
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)
Drupal8 corporate training in Hyderabad
Ad

Recently uploaded (20)

PPTX
TLE Review Electricity (Electricity).pptx
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
August Patch Tuesday
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Architecture types and enterprise applications.pdf
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
The various Industrial Revolutions .pptx
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Tartificialntelligence_presentation.pptx
PPTX
observCloud-Native Containerability and monitoring.pptx
TLE Review Electricity (Electricity).pptx
Web App vs Mobile App What Should You Build First.pdf
A novel scalable deep ensemble learning framework for big data classification...
A contest of sentiment analysis: k-nearest neighbor versus neural network
Hindi spoken digit analysis for native and non-native speakers
cloud_computing_Infrastucture_as_cloud_p
August Patch Tuesday
A comparative study of natural language inference in Swahili using monolingua...
Architecture types and enterprise applications.pdf
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
NewMind AI Weekly Chronicles - August'25-Week II
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Final SEM Unit 1 for mit wpu at pune .pptx
The various Industrial Revolutions .pptx
Developing a website for English-speaking practice to English as a foreign la...
Getting Started with Data Integration: FME Form 101
Group 1 Presentation -Planning and Decision Making .pptx
Tartificialntelligence_presentation.pptx
observCloud-Native Containerability and monitoring.pptx

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
  • 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
  • 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
  • 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