Using Features Drupalcamp Timisoara Alexandru Badiu Iunie 2010
This might have happened to you The dev – staging – production issue You build the site Client wants new stuff You build it on dev, passes staging Replicate on live site Write update functions, manual exporting of views, cck Using Features – Alexandru Badiu
This might have happened to you The “I’ve done this before” issue You build some feature for client A Along comes client B who wants the same thing Take code, exported views, cck, push to dev Work Replicate on prod Using Features – Alexandru Badiu
This might have happened to you The “Is there anyone editing file x.module?” issue You work on a large project Each dev pushes code to a repository What about database changes? Export views, cck and push them as well Make sure each dev imports stuff after each update Using Features – Alexandru Badiu
This might have happened to you The “What the f**k do I do now?” issue Drupal is hard for beginners Lots of modules Building a feature requires multiple modules usually and some knowledge about them Drupal recipes are good Using Features – Alexandru Badiu
Do you see a pattern? Wouldn’t it be nice if you had a repository of “modules” that create functionality a little bit more than “list all blog posts” or “have a block with latest promoted posts in category A”? Learn the open source way Instant gratification Uuuu, this is cool Using Features – Alexandru Badiu
Do you see a pattern? Wouldn’t it be nice if you could avoid all the manual exporting and importing of new features / changes and just package functionality in a “module” that can be updated? Modules are code, code can be put into versioning control Database changes can’t (easily) Using Features – Alexandru Badiu
Do you see a pattern? Just click to generate a new version of the “module“ Check in, others check out, update is done Less wrinkles and teeth grinding Using Features – Alexandru Badiu
So what is the problem? This is not necessarily a Drupal only problem It’s the nature of web development and the way we do it Coding != Site building If only products of site building could be exported… Oh wait Using Features – Alexandru Badiu
So what is the problem? Using Features – Alexandru Badiu
Exportables Exportables are ways of, well, exporting things from Drupal into code bits Pioneered by Views, CCK is also using this Imagecache, Spaces, Context, Strongarm Is this enough? No, replication is still a… not a piece of cake Lots of missing modules (like taxonomy) Using Features – Alexandru Badiu
Modular design It can also help if your site functionality is broken into a modular design Like maybe prefixing presets and views with blog_ or joblistings_ Or use image_blog_medium rather than image_blog_300x50 Or have site_blog.module and site_listings.module rather than that gigantic site.module These are nice first steps Using Features – Alexandru Badiu
Modular design What about blocks? Block visibility: php code or list of pages? Both? Complex conditions? What about menus? I want this menu to appear when you’re on a blog post but I want this other menu to appear on listings. Sitewide conditions: this should appear only if none of the conditions for the other “sections” are met Add more and more sections Using Features – Alexandru Badiu
The Context module Built by Development Seed You create sections for your site They are triggered by various conditions They enable blocks, activate menus They can be global They can act as failbacks They stack http://drupal.org/project/context Using Features – Alexandru Badiu
Almost there We can organize “visual” bits and pieces of our site using contexts We can use the same organization to name the products of our various site building tools We can follow a modular approach when developing our modules If only we could package all these changes into a module. Can it also be easy too? Using Features – Alexandru Badiu
The Features module The Features module does exactly that It takes different clues as to what you want to package There’s the manual way too (it’s not perfect) It exports automatically whatever it can (not all modules use exportables    ) It adds it’s magic Generates a “feature” which is actually a module Using Features – Alexandru Badiu
The Features module The module contains all the necessary bits and pieces about your views, content types, presets etc Contains code to activate them (create or update them) and deactivate them Knows about dependencies so it won’t break the site It’s a module so you can hack away Once you add more stuff: click click => new version of the module Install module on other site, presto Using Features – Alexandru Badiu
The Features module It doesn’t use update functions But you can write your own Doesn’t script site building, uses exportables This means that lots of modules don’t work Webform: uses actual content rather than content types Taxonomy: doesn’t use a machine name but numeric id’s Using Features – Alexandru Badiu
Share A feature can be installed on any other site that has the required modules You can put it on d.org Features server: repository of features Internal or external Get notified of updates Using Features – Alexandru Badiu
Basic usage Simple demo We are going to build a blog feature Use a context to “group” it Create a content type for it Make it use a vocabulary Create a listing and a block using views Package it using Features Deploy it on another site Using Features – Alexandru Badiu
More advanced stuff A bit about a more complex usage scenario CNP – Creative Network Platform Built by Raw Nerve and OpenlyConnected last year Powers three sites:  http://londondesignfestival.com/ ,  http://www.creativeislanduk.com/  and the “never made it” beta of Project: Groundwork Team scattered in 6 cities Build the first site using features, reuse for all other sites and just change small things and do the theme Be careful with the extra things you add in a feature’s code: use drush Using Features – Alexandru Badiu
Even more advanced stuff Almost nothing about the hardcore usage The next step: the Spaces module Again, Development Seed Makes a Drupal site act like multiple sites Makes features spaces aware: selective enabling of features on a per group basis Using Features – Alexandru Badiu
Resources http://drupal.org/project/features http://drupal.org/node/580026 http://drupal.org/project/context http://drupal.org/project/spaces http://groups.drupal.org/packaging-deployment http://developmentseed.org/tags/features Using Features – Alexandru Badiu
Alexandru Badiu Thanks [email_address] http://plan9fromweb.com http://corporate.adulmec.com

Using Features

  • 1.
    Using Features DrupalcampTimisoara Alexandru Badiu Iunie 2010
  • 2.
    This might havehappened to you The dev – staging – production issue You build the site Client wants new stuff You build it on dev, passes staging Replicate on live site Write update functions, manual exporting of views, cck Using Features – Alexandru Badiu
  • 3.
    This might havehappened to you The “I’ve done this before” issue You build some feature for client A Along comes client B who wants the same thing Take code, exported views, cck, push to dev Work Replicate on prod Using Features – Alexandru Badiu
  • 4.
    This might havehappened to you The “Is there anyone editing file x.module?” issue You work on a large project Each dev pushes code to a repository What about database changes? Export views, cck and push them as well Make sure each dev imports stuff after each update Using Features – Alexandru Badiu
  • 5.
    This might havehappened to you The “What the f**k do I do now?” issue Drupal is hard for beginners Lots of modules Building a feature requires multiple modules usually and some knowledge about them Drupal recipes are good Using Features – Alexandru Badiu
  • 6.
    Do you seea pattern? Wouldn’t it be nice if you had a repository of “modules” that create functionality a little bit more than “list all blog posts” or “have a block with latest promoted posts in category A”? Learn the open source way Instant gratification Uuuu, this is cool Using Features – Alexandru Badiu
  • 7.
    Do you seea pattern? Wouldn’t it be nice if you could avoid all the manual exporting and importing of new features / changes and just package functionality in a “module” that can be updated? Modules are code, code can be put into versioning control Database changes can’t (easily) Using Features – Alexandru Badiu
  • 8.
    Do you seea pattern? Just click to generate a new version of the “module“ Check in, others check out, update is done Less wrinkles and teeth grinding Using Features – Alexandru Badiu
  • 9.
    So what isthe problem? This is not necessarily a Drupal only problem It’s the nature of web development and the way we do it Coding != Site building If only products of site building could be exported… Oh wait Using Features – Alexandru Badiu
  • 10.
    So what isthe problem? Using Features – Alexandru Badiu
  • 11.
    Exportables Exportables areways of, well, exporting things from Drupal into code bits Pioneered by Views, CCK is also using this Imagecache, Spaces, Context, Strongarm Is this enough? No, replication is still a… not a piece of cake Lots of missing modules (like taxonomy) Using Features – Alexandru Badiu
  • 12.
    Modular design Itcan also help if your site functionality is broken into a modular design Like maybe prefixing presets and views with blog_ or joblistings_ Or use image_blog_medium rather than image_blog_300x50 Or have site_blog.module and site_listings.module rather than that gigantic site.module These are nice first steps Using Features – Alexandru Badiu
  • 13.
    Modular design Whatabout blocks? Block visibility: php code or list of pages? Both? Complex conditions? What about menus? I want this menu to appear when you’re on a blog post but I want this other menu to appear on listings. Sitewide conditions: this should appear only if none of the conditions for the other “sections” are met Add more and more sections Using Features – Alexandru Badiu
  • 14.
    The Context moduleBuilt by Development Seed You create sections for your site They are triggered by various conditions They enable blocks, activate menus They can be global They can act as failbacks They stack http://drupal.org/project/context Using Features – Alexandru Badiu
  • 15.
    Almost there Wecan organize “visual” bits and pieces of our site using contexts We can use the same organization to name the products of our various site building tools We can follow a modular approach when developing our modules If only we could package all these changes into a module. Can it also be easy too? Using Features – Alexandru Badiu
  • 16.
    The Features moduleThe Features module does exactly that It takes different clues as to what you want to package There’s the manual way too (it’s not perfect) It exports automatically whatever it can (not all modules use exportables  ) It adds it’s magic Generates a “feature” which is actually a module Using Features – Alexandru Badiu
  • 17.
    The Features moduleThe module contains all the necessary bits and pieces about your views, content types, presets etc Contains code to activate them (create or update them) and deactivate them Knows about dependencies so it won’t break the site It’s a module so you can hack away Once you add more stuff: click click => new version of the module Install module on other site, presto Using Features – Alexandru Badiu
  • 18.
    The Features moduleIt doesn’t use update functions But you can write your own Doesn’t script site building, uses exportables This means that lots of modules don’t work Webform: uses actual content rather than content types Taxonomy: doesn’t use a machine name but numeric id’s Using Features – Alexandru Badiu
  • 19.
    Share A featurecan be installed on any other site that has the required modules You can put it on d.org Features server: repository of features Internal or external Get notified of updates Using Features – Alexandru Badiu
  • 20.
    Basic usage Simpledemo We are going to build a blog feature Use a context to “group” it Create a content type for it Make it use a vocabulary Create a listing and a block using views Package it using Features Deploy it on another site Using Features – Alexandru Badiu
  • 21.
    More advanced stuffA bit about a more complex usage scenario CNP – Creative Network Platform Built by Raw Nerve and OpenlyConnected last year Powers three sites: http://londondesignfestival.com/ , http://www.creativeislanduk.com/ and the “never made it” beta of Project: Groundwork Team scattered in 6 cities Build the first site using features, reuse for all other sites and just change small things and do the theme Be careful with the extra things you add in a feature’s code: use drush Using Features – Alexandru Badiu
  • 22.
    Even more advancedstuff Almost nothing about the hardcore usage The next step: the Spaces module Again, Development Seed Makes a Drupal site act like multiple sites Makes features spaces aware: selective enabling of features on a per group basis Using Features – Alexandru Badiu
  • 23.
    Resources http://drupal.org/project/features http://drupal.org/node/580026http://drupal.org/project/context http://drupal.org/project/spaces http://groups.drupal.org/packaging-deployment http://developmentseed.org/tags/features Using Features – Alexandru Badiu
  • 24.
    Alexandru Badiu Thanks[email_address] http://plan9fromweb.com http://corporate.adulmec.com