Making and Using Features in Drupal

Nguyen Tien Si

GO1

Why?

Features?

Image source: https://www.drupal.org/node/580026

Key features

  • Deployment
  • Reusable
  • Versioning

Updating, modifying and reverting Features

  • Feature X
  • Feature Y
  • Feature Z

Pros and Cons

Pros

  • Can export almost components in Drupal to features
  • Easy to use: UI, Click and Click
  • Easy to deploy: Install & revert to stable configuration if have something wrong
  • It can be easily stored in version control
  • It can be debugged
  • It can be “diffed”
  • It has separation of content and configuration
  • Better for teamwork

Cons

  • Hard or Can't export dynamic content to features: Node, User, Taxonomy, Block.
  • Sometime have problem with menu link when site already is running on production.
  • Can't revert features when edit field option value (eg: CROM project)
  • Big problem with:
    • ​No drush
    • All in one features

Naming & Structure

//Depend on JIRA key
//Example: SBH project
//If project is small and just has one features, should be:

  modules/
    contrib/
    custom/
    features/
      sbhf/ //main features 

//If project is big and have many features (like GC, Aduro), should be:

  modules/
    contrib/
    custom/
    features/
      sbh_core/ //core features
      sbh_blog/ //sub features

Deploy Workflow

Workflow

  • Dev
  • Stage
  • Prod

Code: Dev -> Stage -> Prod

Database: Prod -> Stage -> Dev

Tips & Best Practices

Menu Link

Avoid export menu link (dynamic content) into the features

// Dev site

features[menu_links][] = menu-header-menu_help:node/10 
//node/10 point to Help page

// Stage site
features[menu_links][] = menu-header-menu_help:node/10 
//node/10 point to other page

// Prod site
features[menu_links][] = menu-header-menu_help:node/10 
//node/10 point to other page

// So when deploy should be fail if don't have same database.

Development module

Avoid export development module into features

// Don't need development module on prod.

dependencies[] = devel

Field Option

Avoid change value of field option in field config

// Dev

foo|FOO

// Stage

FOO|FOO

// Should be fail when reverting

Solr server

Do not export solr server to features

// Dev site
URI: http://example-d.com/solr/drupal
Host: example.com
Protocol: http
Port: 80
Path: /solr/drupal

// Stage site
URI: https://example-s.com/solr/drupal
 
Host: example-s.com
Protocol: https
Port: 443
Path: /solr/drupal
User: user
Pass: [secret]

What's next?

Config management in Drupal 8

Features in Drupal 8

References

Questions?

Making and Using Features in Drupal

By Nguyen Tien Si

Making and Using Features in Drupal

Making and Using Features in Drupal

  • 892