drupal presentation for capitalcamp 2011: features driven development
DESCRIPTION
Mediacurrent's Jay Callicott reviews and analyzes how to leverage Features within Drupal at CapitalCamp 2011 in Washington D.C.TRANSCRIPT
Features Everywhere!
Feature Driven Development
By Jay CallicottMediacurrent ConsultantCapitalCamp 2011July 22, 2011
Features Everywhere! Outline
• Part I - The Basicso About Featureso About Jayo The Problemo The Solutiono How to Create a Basic Feature
• Part 2 - Diving Deepero Context & Featureso Panels & Featureso Adding stuff that isn't exportableo Feature Driven Developmento Real World Examples!
About Features
• Recommended ReadingManaging and deploying configuration with exportables
and the Features module - DrupalCon presentation by Jeff Miccolis of Development SeedMaking and Using Features in Drupal - Blog by Young
Hahn of Development Seed• Who Uses Features?
o Originally created by DevelopmentSeedUsed extensively in OpenAtrium
o Phase2Used extensively in OpenPublishNow maintained by Phase2
About FeaturesOpenAtrium
About Features
About Jay
• Mediacurrent Web Developer• Developed Drupal sites since version 4.6• Why Features?
o Started using features in early 2010o Developed features extensively on a large OpenPublish-
based multi-site installation, working with Phase2o Now use features on every site big and small
• OpenChurch distribution maintainero Features used extensively
The Problem
• Drupal has many items in the databaseo Viewso CCK Content typeso Imagecacheo Contexto Panelso Settingso Permissions
• Moving these between environments is cumbersome• Backing these up is a pain• No version control• Developers can accidentally override each other's work
The Solution - Features!
• Features' Benefits:o Work more in the „problem space‟o Encapsulation - Yes!o Backup - Yes!o Version Control - Yes!o Easier deploymento Code reuse!o A place for your form_alters and nodeapi() hookso Drush integration
• And much, much more!o Replace (or supplement) install profiles! Features break an install into components
o Create a distribution with drush .make (music site, newspaper site, govt, blog, etc)
How to Create a Feature
• Install and Enable the Following:o Featureso Strongarm (important) Saves additional settings with your content types that
would otherwise not get saveo ContextRecommended over admin/build/block
o Diff (recommended, only on non-production environments)Can view differences in code
How to Create a Feature
Go to /admin/build/features
(Sample screen)
How to Create a FeatureGo to /admin/build/features/create and add components
How to Create a Feature
Click download and save tar file to hard drive (this contains feature module files)
How to Create a FeatureExtract your feature folder to your project (screenshot showing 7zip on Windows 7)
How to Create a Feature
Add/commit to svn/git, svn up and enable on your Drupal site
How to Create a Feature
Your views, content types, etc will now be enabled, you have just deployed a feature!
How to Create a Feature
To update use drush features-update + svn commit to update your features or 'recreate' for additions (new views, etc)
How to Create a Feature
Revert components if you a) updated a feature on another environment or b) want to restore a feature to it's original state
Context & Features
• http://drupal.org/project/context• Context is used primarily for block
placement (admin/build/block replacement)• Exports to features out of the box
Screenshots next....
Context Example Screenshot
Adding Context to a Feature
Panels & Features
• Panels export to features easilyoFalls under 'Panels' or 'Page Manager' in
dropdown in components• I like panels for node layouts!
o (overriding page manager node template)
Screenshots next....
Panels Feature Example
context placed blocks
panel regions & views
Panels Feature Underneath...
Panel Feature Underneath
Using CCK, views, panel, strongarm
Adding a Panel to a Feature
under "Panels" or "Page Manager"
How to export non-exportables
• Features doesn't export everything, but it's still a module!
• Next: simple example, creating a vocabulary with a featureo (Note: features_extra does this for you)
How to export non-exportables
• Anything you can do in a module you can do in a feature
Using hook_install() & hook_uninstall()
Feature Driven Development
• My methodology (adapted from OpenAtrium, DevSeed, OpenPublish)o Create a feature for every content typeo Package with any related viewso Package panels and node template overrides!o Package relevant imagecache presetso Sometimes directly related permissionso Sometimes package related contextso Place all related form_alters, nodeapi hooks,
hook_menus(), etc in the .module file• That's it!
Real World Examples!
• Seeing is believing, some (more) real world screenshots of feature lists
Real World List Screenshots
Real World List Screenshots
Real World List Screenshots
Real World Screenshots
The trend is I always have at least 1 feature for each content type
Wait! A couple last items to cover
• Features Extra• Drush Make• Distributions with .make• Features Server
• Share Features!• Drupal “Apps”(introduced by Ph2)• What about Drupal 7?• I'm a beginner – is this for me?
The End
Resources• Features Project Page
o http://drupal.org/project/features• Features Extra Project Page
o http://drupal.org/project/features_extra
Related• From Zero to Distribution using Features, Profiler, and
Drush Makeo http://chicago2011.drupal.org/sessions/zero-
distribution-using-features-profiler-and-drush-make
Hit me up on twitter: http://twitter.com/drupalninja/
Questions??