THE LEADER IN DRUPAL PLATFORM DESIGN AND DEVELOPMENTWednesday, November 7, 12
BUILDING AND DEPLOYING            SITES USING FEATURES2.0Wednesday, November 7, 12
BUILDING AND DEPLOYING SITES USING FEATURES       • Mike Potter         Phase2 Technology       • Maintainer of Features a...
OVERVIEW         • What is Features?         • What’s new in Features 2.0?         • Features OverrideWednesday, November ...
DRUPAL ARCHITECTURE                            Web Server               Web                            Database           ...
DRUPAL ARCHITECTURE                            Web Server               Web                            Database           ...
DRUPAL ARCHITECTURE                            Web Server               Web                            Database           ...
DRUPAL ARCHITECTURE                            Web Server               Web                            Database           ...
DRUPAL ARCHITECTURE                            Web Server               Web                            Database           ...
DRUPAL ARCHITECTURE                            Web Server               Web                            Database           ...
DRUPAL ARCHITECTURE                            Web Server               Web                            Database           ...
FEATURES       • Brings configuration from the Database into Code.                                    (called an exportable...
WHY?          • Separates Site configuration from Site content.          • Encapsulates functionality into a package that c...
EXPORTABLE TYPES        • Content Types, Fields, Menus, Taxonomies,          Text formats, Image styles, User roles and   ...
USAGE CASES         • Bundle some functionality into a Feature           e.g. Photo Gallery           contains Content Typ...
DEMO TIME !Wednesday, November 7, 12
/admin/structure/features/create     MAKE A     NEW     FEATUREWednesday, November 7, 12
FEATURES 2.0 UI      • User Interface redesign      • Removed Ajax      • Expand fieldset you wish        to add to exportW...
NEW FEATURES      • Searching      • Select-All      • Can remove auto-detected        items from exportWednesday, Novembe...
AMP                       BA   DCWednesday, November 7, 12
NEW ADVANCED OPTIONS      • Export code directly to site        (drush fu)      • Control dependancies      • Better item ...
CONFLICTS  •      Shows ALL components  •      Shows used items in red  •      Can export what you want  •      Remove dep...
NEW HOOKS         • Added hooks for:               •      hook_pre_features_revert($component)               •      hook_p...
FEATURE IS A MODULE              • Downloading a Feature creates .tar package              • Install just like any normal ...
IT’S ALL IN THE CODE!                                                          the “default hook”                         ...
IT’S ALL (MOSTLY) IN THE CODE!        • “Pure” Exportables         • “Faux” exportables          - all in code            ...
UPDATING A FEATURE        • Make a manual change to   • “Recreate” the feature to          the database                add...
REVERT VS RECREATE                                Revert                                           Database               ...
USING DRUSH WITH FEATURES           • If anybody doesn’t know about Drush             then time for a quick DEMO!         ...
REVERTING FEATURES USING DRUSH       $ drush     fl        Name                 Feature          Status     State        D...
REVERTING FEATURES USING DRUSH - 2        Keep RED Code (Code Database)        $ drush fr distro_view        Do you really...
DEBUGGING OVERRIDDEN FEATURES      When Reverting fails to remove Overridden        •      Use “drush fd” to see what is d...
FEATURES SERVER        drupal.org/project/fserver          • Allows features to be shared, distributed and            upda...
APPS               drupal.org/project/apps        • An App is a Feature(s) along with a manifest that          allows it t...
OVERRIDES         • Using a Feature that you don’t want to change?                (e.g. comes from a base Distribution lik...
FEATURES OVERRIDE MODULE    • Rewritten for D7 to be easier to use    • Generates simple code for overrides    • Allows li...
FEATURES OVERRIDE DEMO                            I can’t look!Wednesday, November 7, 12
EXTRA DOUBLE-SECRET PROBATION DEMO        • Change a View        • Add a field to a View        • Remove a field from a     ...
INSPECTING OVERRIDES      • Old method (Review Overrides using diff module)Wednesday, November 7, 12
INSPECTING OVERRIDES   • New method (Overrides using Features Override)Wednesday, November 7, 12
FEATURES IN D8         • Features will still need to exist in D8         • Will coordinate with CMI           (Configuratio...
WHAT DOES THIS ALL MEAN? (CASE 1)      • Use a Distribution containing features.      • Customize site for specific Client ...
WHAT DOES THIS ALL MEAN? (CASE 2)    • Build site for client using Features.    • Deploy from your Dev server to Staging. ...
BOTTOM LINE     • Use Features. They will save you.     • Use Overrides. They will make you a star!                       ...
Upcoming SlideShare
Loading in...5
×

Build and Deploy Sites Using Features

1,019
-1

Published on

Mike Potter presentation at BADCamp about Features

Build and Deploy Sites Using Features

  1. 1. THE LEADER IN DRUPAL PLATFORM DESIGN AND DEVELOPMENTWednesday, November 7, 12
  2. 2. BUILDING AND DEPLOYING SITES USING FEATURES2.0Wednesday, November 7, 12
  3. 3. BUILDING AND DEPLOYING SITES USING FEATURES • Mike Potter Phase2 Technology • Maintainer of Features and Features Override modules • mpotter on Drupal.org mpotter@phase2technology.com • #drupal-features IRC channelWednesday, November 7, 12
  4. 4. OVERVIEW • What is Features? • What’s new in Features 2.0? • Features OverrideWednesday, November 7, 12
  5. 5. DRUPAL ARCHITECTURE Web Server Web Database Browser File System ConfigurationWednesday, November 7, 12
  6. 6. DRUPAL ARCHITECTURE Web Server Web Database Browser File System Code ConfigurationWednesday, November 7, 12
  7. 7. DRUPAL ARCHITECTURE Web Server Web Database Browser Content File System Code ConfigurationWednesday, November 7, 12
  8. 8. DRUPAL ARCHITECTURE Web Server Web Database Browser Content File System Configuration Code ConfigurationWednesday, November 7, 12
  9. 9. DRUPAL ARCHITECTURE Web Server Web Database Browser Content File System Configuration Code ConfigurationWednesday, November 7, 12
  10. 10. DRUPAL ARCHITECTURE Web Server Web Database Browser Content File System Code ConfigurationWednesday, November 7, 12
  11. 11. DRUPAL ARCHITECTURE Web Server Web Database Browser Content File System Code Configuration FEATURESWednesday, November 7, 12
  12. 12. FEATURES • Brings configuration from the Database into Code. (called an exportable) • A Feature is a Drupal Module. • The Features Module provides a User Interface for manipulating features.Wednesday, November 7, 12
  13. 13. WHY? • Separates Site configuration from Site content. • Encapsulates functionality into a package that can be used on multiple sites. • Allows version control (track changes, revert, etc). • Easier deployment. • Saves development time!!Wednesday, November 7, 12
  14. 14. EXPORTABLE TYPES • Content Types, Fields, Menus, Taxonomies, Text formats, Image styles, User roles and permissions, Views, CTools, Context CORE • System variables (Strongarm) • Node queues, Boxes (blocks), Nodes (content), Panels, Commerce products, many more. • Any module can support exporting as Feature.Wednesday, November 7, 12
  15. 15. USAGE CASES • Bundle some functionality into a Feature e.g. Photo Gallery contains Content Type, Fields, Views • Deploy configuration data using a Feature e.g. Transfer user permissions from Dev server to Production.Wednesday, November 7, 12
  16. 16. DEMO TIME !Wednesday, November 7, 12
  17. 17. /admin/structure/features/create MAKE A NEW FEATUREWednesday, November 7, 12
  18. 18. FEATURES 2.0 UI • User Interface redesign • Removed Ajax • Expand fieldset you wish to add to exportWednesday, November 7, 12
  19. 19. NEW FEATURES • Searching • Select-All • Can remove auto-detected items from exportWednesday, November 7, 12
  20. 20. AMP BA DCWednesday, November 7, 12
  21. 21. NEW ADVANCED OPTIONS • Export code directly to site (drush fu) • Control dependancies • Better item conflict handling • Preview info file • New tar file formatWednesday, November 7, 12
  22. 22. CONFLICTS • Shows ALL components • Shows used items in red • Can export what you want • Remove dependancies you don’t wantWednesday, November 7, 12
  23. 23. NEW HOOKS • Added hooks for: • hook_pre_features_revert($component) • hook_post_features_revert($component) • hook_pre_features_rebuild($component) • hook_post_features_rebuild($component) • hook_pre_features_disable_feature($component) • hook_post_features_disable_feature($component) • hook_pre_features_enable_feature($component) • hook_post_features_enable_feature($component) • Implemented within a Feature module fileWednesday, November 7, 12
  24. 24. FEATURE IS A MODULE • Downloading a Feature creates .tar package • Install just like any normal module • Enable the module /sites/all/modules/featuresWednesday, November 7, 12
  25. 25. IT’S ALL IN THE CODE! the “default hook” cats.info cats.features.inc name = Cats /** description = Description of Cats feature * Implements hook_node_info(). core = 7.x */ package = Cat Package function cats_node_info() { php = 5.2.4 $items = array( dependencies[] = features cat => array( dependencies[] = image name => t(Cat), dependencies[] = link base => node_content, dependencies[] = node_reference description => , eatures[features_api][] = api:1 has_title => 1, features[field][] = node-cat-body title_label => t(Name), features[field][] = node-cat-field_age help => , features[field][] = node-cat-field_cat_image ), features[field][] = node-cat-field_test_link ); features[field][] = node-cat-field_test_ref return $items; features[node][] = cat } Features will keep your changes to *.module and any other files you addWednesday, November 7, 12
  26. 26. IT’S ALL (MOSTLY) IN THE CODE! • “Pure” Exportables • “Faux” exportables - all in code - some code - nothing in DB - some config in DB • Views, CTools, etc • Fields uses existing module requires Features hooks don’t need FeaturesWednesday, November 7, 12
  27. 27. UPDATING A FEATURE • Make a manual change to • “Recreate” the feature to the database add new data to code configuration or • “Revert” the feature to • Feature exportable is restore original config marked as “Overridden” clickWednesday, November 7, 12
  28. 28. REVERT VS RECREATE Revert Database Code on disk RecreateWednesday, November 7, 12
  29. 29. USING DRUSH WITH FEATURES • If anybody doesn’t know about Drush then time for a quick DEMO! drupal.org/projects/drush All commands in features: (features) features-add (fa) Add a component to a feature module. features-diff (fd) Show the difference between the default and overridden state of a feature. features-export (fe) Export a feature from your site into a module. features-list (fl, List all the available features for your site. features) features-revert (fr) Revert a feature module on your site. features-revert-all Revert all enabled feature module on your site. (fr-all, fra) features-update (fu) Update a feature module on your site. features-update-all Update all feature modules on your site. (fu-all, fua)Wednesday, November 7, 12
  30. 30. REVERTING FEATURES USING DRUSH $ drush fl Name Feature Status State Distro Article distro_article Enabled Distro User distro_user Disabled Distro View distro_view Enabled Overridden $ drush fd distro_view Legend: Code: drush features-revert will remove the overrides. RED is Code Overrides: drush features-update will update the exported feature with the displayed overrides Component: views_view GREEN is Database /* Display: Master */ $handler = $view->new_display(default, Master, default); < $handler->display->display_options[title] = My Cat List; --- > $handler->display->display_options[title] = My Cat List New; $handler->display->display_options[access][type] = perm; $handler->display->display_options[cache][type] = none;Wednesday, November 7, 12
  31. 31. REVERTING FEATURES USING DRUSH - 2 Keep RED Code (Code Database) $ drush fr distro_view Do you really want to revert views_view? (y/n): y Reverted views_view. Keep GREEN Database (Database Code) $ drush fu distro_view Module appears to already exist in sites/all/modules/features/distro_view Do you really want to continue? (y/n): y Created module: distro_view in sites/all/modules/features/distro_viewWednesday, November 7, 12
  32. 32. DEBUGGING OVERRIDDEN FEATURES When Reverting fails to remove Overridden • Use “drush fd” to see what is different • Make sure difference isn’t provided by a disabled module. • If a View, try Reverting from the Views UI • Ensure there isn’t a left-over file in the feature directory • Last resort: try editing code manually, or making database change manually to match code.Wednesday, November 7, 12
  33. 33. FEATURES SERVER drupal.org/project/fserver • Allows features to be shared, distributed and updated. • No longer in wide use because of alternatives: drupal.org sandboxes, github, and AppsWednesday, November 7, 12
  34. 34. APPS drupal.org/project/apps • An App is a Feature(s) along with a manifest that allows it to be distributed via an App Server. • An App is a clean, polished, modular piece of functionality. • Apps are currently used mostly by Distributions to supply optional functionality.Wednesday, November 7, 12
  35. 35. OVERRIDES • Using a Feature that you don’t want to change? (e.g. comes from a base Distribution like OpenPublish) • Client made site-specific configuration changes? • Capture those changes into a NEW feature called an “Override”Wednesday, November 7, 12
  36. 36. FEATURES OVERRIDE MODULE • Rewritten for D7 to be easier to use • Generates simple code for overrides • Allows line-level inspection of overrides • Uses existing “alter” hooks drupal_alter(‘default_hook’, $data); Called by Drupal function override_feature_views_default_views_alter(&$data) { if (isset($data[cat_fields])) { $data[cat_fields]->display[default]->display_options[title] = New Cat View title; /* WAS: My Cat List */ } } Code in Override featureWednesday, November 7, 12
  37. 37. FEATURES OVERRIDE DEMO I can’t look!Wednesday, November 7, 12
  38. 38. EXTRA DOUBLE-SECRET PROBATION DEMO • Change a View • Add a field to a View • Remove a field from a View • All in ONE Override!Wednesday, November 7, 12
  39. 39. INSPECTING OVERRIDES • Old method (Review Overrides using diff module)Wednesday, November 7, 12
  40. 40. INSPECTING OVERRIDES • New method (Overrides using Features Override)Wednesday, November 7, 12
  41. 41. FEATURES IN D8 • Features will still need to exist in D8 • Will coordinate with CMI (Configuration Management Initiative) • Use CMI API as much as possible. • Still need to be able bundle functionality and deploy it to a siteWednesday, November 7, 12
  42. 42. WHAT DOES THIS ALL MEAN? (CASE 1) • Use a Distribution containing features. • Customize site for specific Client needs. • Capture changes to a Features Override. • New version of Distribution released? • Just install new features • Site-specific changes are maintained in Override.Wednesday, November 7, 12
  43. 43. WHAT DOES THIS ALL MEAN? (CASE 2) • Build site for client using Features. • Deploy from your Dev server to Staging. • Deploy from Staging to Production. • Client makes emergency changes to live Production. • Capture those changes into Features Override • Keep separate or roll back into Dev featuresWednesday, November 7, 12
  44. 44. BOTTOM LINE • Use Features. They will save you. • Use Overrides. They will make you a star! QUESTIONS? #drupal-features mpotter@phase2technology.comWednesday, November 7, 12
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×