Features Everywhere!
           Feature Driven Development


By Jay Callicott
Mediacurrent Consultant
CapitalCamp 2011
July 22, 2011
Features Everywhere! Outline
• Part I - The Basics
  o About Features
  o About Jay
  o The Problem
  o The Solution
  o How to Create a Basic Feature
• Part 2 - Diving Deeper
  o Context & Features
  o Panels & Features
  o Adding stuff that isn't exportable
  o Feature Driven Development
  o Real World Examples!
About Features

• Recommended Reading
      Managing and deploying configuration with exportables
       and the Features module - DrupalCon presentation by
       Jeff Miccolis of Development Seed
      Making and Using Features in Drupal - Blog by Young
       Hahn of Development Seed
• Who Uses Features?
  o Originally created by DevelopmentSeed
      Used extensively in OpenAtrium
  o Phase2
      Used extensively in OpenPublish
      Now maintained by Phase2
About Features
OpenAtrium
About Features
About Jay
• Mediacurrent Web Developer
• Developed Drupal sites since version 4.6
• Why Features?
  o Started using features in early 2010
  o Developed features extensively on a large OpenPublish-
    based multi-site installation, working with Phase2
  o Now use features on every site big and small
• OpenChurch distribution maintainer
  o Features used extensively
The Problem

• Drupal has many items in the database
   o Views
   o CCK Content types
   o Imagecache
   o Context
   o Panels
   o Settings
   o 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 deployment
   o Code reuse!
   o A place for your form_alters and nodeapi() hooks
   o 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 Features
   o Strongarm (important)
       Saves additional settings with your content types that
        would otherwise not get save
   o Context
       Recommended 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 Feature
Go 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 Feature
Extract 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 easily
   o Falls 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 feature
  o (Note: features_extra does this for you)
How to export non-exportables

                                   Using hook_install() &
                                   hook_uninstall()




• Anything you can do in a module you can do in a feature
Feature Driven Development
• My methodology (adapted from OpenAtrium,
  DevSeed, OpenPublish)
  o Create a feature for every content type
  o Package with any related views
  o Package panels and node template overrides!
  o Package relevant imagecache presets
  o Sometimes directly related permissions
  o Sometimes package related contexts
  o 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 Make
   o http://chicago2011.drupal.org/sessions/zero-
     distribution-using-features-profiler-and-drush-make

Hit me up on twitter: http://twitter.com/drupalninja/

Questions??

Drupal Presentation for CapitalCamp 2011: Features Driven Development

  • 1.
    Features Everywhere! Feature Driven Development By Jay Callicott Mediacurrent Consultant CapitalCamp 2011 July 22, 2011
  • 2.
    Features Everywhere! Outline •Part I - The Basics o About Features o About Jay o The Problem o The Solution o How to Create a Basic Feature • Part 2 - Diving Deeper o Context & Features o Panels & Features o Adding stuff that isn't exportable o Feature Driven Development o Real World Examples!
  • 3.
    About Features • RecommendedReading  Managing and deploying configuration with exportables and the Features module - DrupalCon presentation by Jeff Miccolis of Development Seed  Making and Using Features in Drupal - Blog by Young Hahn of Development Seed • Who Uses Features? o Originally created by DevelopmentSeed  Used extensively in OpenAtrium o Phase2  Used extensively in OpenPublish  Now maintained by Phase2
  • 4.
  • 5.
  • 6.
    About Jay • MediacurrentWeb Developer • Developed Drupal sites since version 4.6 • Why Features? o Started using features in early 2010 o Developed features extensively on a large OpenPublish- based multi-site installation, working with Phase2 o Now use features on every site big and small • OpenChurch distribution maintainer o Features used extensively
  • 7.
    The Problem • Drupalhas many items in the database o Views o CCK Content types o Imagecache o Context o Panels o Settings o Permissions • Moving these between environments is cumbersome • Backing these up is a pain • No version control • Developers can accidentally override each other's work
  • 8.
    The Solution -Features! • Features' Benefits: o Work more in the „problem space‟ o Encapsulation - Yes! o Backup - Yes! o Version Control - Yes! o Easier deployment o Code reuse! o A place for your form_alters and nodeapi() hooks o 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)
  • 9.
    How to Createa Feature • Install and Enable the Following: o Features o Strongarm (important)  Saves additional settings with your content types that would otherwise not get save o Context  Recommended over admin/build/block o Diff (recommended, only on non-production environments)  Can view differences in code
  • 10.
    How to Createa Feature Go to /admin/build/features (Sample screen)
  • 11.
    How to Createa Feature Go to /admin/build/features/create and add components
  • 12.
    How to Createa Feature Click download and save tar file to hard drive (this contains feature module files)
  • 13.
    How to Createa Feature Extract your feature folder to your project (screenshot showing 7zip on Windows 7)
  • 14.
    How to Createa Feature Add/commit to svn/git, svn up and enable on your Drupal site
  • 15.
    How to Createa Feature Your views, content types, etc will now be enabled, you have just deployed a feature!
  • 16.
    How to Createa Feature To update use drush features-update + svn commit to update your features or 'recreate' for additions (new views, etc)
  • 17.
    How to Createa Feature Revert components if you a) updated a feature on another environment or b) want to restore a feature to it's original state
  • 18.
    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....
  • 19.
  • 20.
  • 21.
    Panels & Features •Panels export to features easily o Falls under 'Panels' or 'Page Manager' in dropdown in components • I like panels for node layouts! o (overriding page manager node template) Screenshots next....
  • 22.
  • 23.
  • 24.
    Panel Feature Underneath UsingCCK, views, panel, strongarm
  • 25.
    Adding a Panelto a Feature under "Panels" or "Page Manager"
  • 26.
    How to exportnon-exportables • Features doesn't export everything, but it's still a module! • Next: simple example, creating a vocabulary with a feature o (Note: features_extra does this for you)
  • 27.
    How to exportnon-exportables Using hook_install() & hook_uninstall() • Anything you can do in a module you can do in a feature
  • 28.
    Feature Driven Development •My methodology (adapted from OpenAtrium, DevSeed, OpenPublish) o Create a feature for every content type o Package with any related views o Package panels and node template overrides! o Package relevant imagecache presets o Sometimes directly related permissions o Sometimes package related contexts o Place all related form_alters, nodeapi hooks, hook_menus(), etc in the .module file • That's it!
  • 29.
    Real World Examples! •Seeing is believing, some (more) real world screenshots of feature lists
  • 30.
    Real World ListScreenshots
  • 31.
    Real World ListScreenshots
  • 32.
    Real World ListScreenshots
  • 33.
    Real World Screenshots Thetrend is I always have at least 1 feature for each content type
  • 34.
    Wait! A couplelast 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?
  • 35.
    The End Resources • FeaturesProject 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 Make o http://chicago2011.drupal.org/sessions/zero- distribution-using-features-profiler-and-drush-make Hit me up on twitter: http://twitter.com/drupalninja/ Questions??