Drupal Presentation for CapitalCamp 2011: Features Driven Development
Features Everywhere! Feature Driven DevelopmentBy Jay CallicottMediacurrent ConsultantCapitalCamp 2011July 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 isnt 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 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 others 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 FeatureGo to /admin/build/features (Sample screen)
How to Create a FeatureGo to /admin/build/features/create and add components
How to Create a FeatureClick download and save tar file to hard drive (this containsfeature module files)
How to Create a FeatureExtract your feature folder to your project (screenshot showing7zip on Windows 7)
How to Create a FeatureAdd/commit to svn/git, svn up and enable on your Drupal site
How to Create a FeatureYour views, content types, etc will now be enabled, you havejust deployed a feature!
How to Create a FeatureTo update use drush features-update + svn commit to updateyour features or recreate for additions (new views, etc)
How to Create a FeatureRevert components if you a) updated a feature on anotherenvironment or b) want to restore a feature to its 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....
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 Examplecontextplacedblocks panel regions & views
Adding a Panel to a Feature under "Panels" or "Page Manager"
How to export non-exportables• Features doesnt export everything, but its 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• Thats it!
Real World Examples!• Seeing is believing, some (more) real world screenshots of feature lists
Real World ScreenshotsThe trend is I alwayshave at least 1feature for eachcontent 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?• Im a beginner – is this for me?
The EndResources• Features Project Page o http://drupal.org/project/features• Features Extra Project Page o http://drupal.org/project/features_extraRelated• From Zero to Distribution using Features, Profiler, and Drush Make o http://chicago2011.drupal.org/sessions/zero- distribution-using-features-profiler-and-drush-makeHit me up on twitter: http://twitter.com/drupalninja/Questions??
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.