Features & the Features Builder

Drupal Chicago General Meetup

January 21, 2016

About Me

Will Long

Objectives

  • Obtain a basic understanding of Features
  • Understand the operation of Features Builder
  • Use Features Builder to manage your Features modules
  • Customize/enhance the Features Builder packaging scheme

Agenda

  • Brief Features Primer
  • What is Features Builder
  • Features Builder Usage

What is Features?

Credit: Aimee Degnan - Hook 42

Features

The Basics

  • Analyze a site's configuration
  • Write code representing configuration
  • Set configuration as defined in files

Features Integrated Modules

Features Integration

  • hook_features_api()
  • hook_features_export()
  • hook_features_export_options()
  • hook_features_export_render()
  • hook_features_revert()
  • hook_features_rebuild()

See features.api.php.

Feature Modules

  • Just like any other module
  • Written by Features
  • Additional metadata in .info file
  • Various .inc files
  • Implements default hooks

Recap

  • Features Module
  • Features-Integrated Modules
  • Feature Modules
  • Component Types
  • Components

Working with Features

Faux-Exportable

Exportable

Feature States

  • Default
  • Overridden
  • Needs Review
  • Rebuilding
  • Conflict

Overridden

Feature Update

Write Your Configuration to Code

Feature Revert

Use Configuration from Code

Feature Revert

Use Configuration from Code

Architecting Features

Function-Based Architecture

Image Gallery

  • Content Type: Image
  • Field: field_image
  • Permissions: Image add/edit/delte
  • View: slideshow
  • Dependency: Flexslider
  • Dependency: Image
  • Dependency: Views

Component-Based Architecture

  • Fields
  • General Site Config
  • Media
  • SEO
  • Node Type
  • Taxonomy
  • Users
  • Panels
  • Views

Strongarm

Drupal Variables

  • Site name, slogan
  • Default publishing options

Diff

Drush

Use it.

Use it a lot.

Then use it more.

Drush

  • drush fl
  • drush fdiff
  • drush fu
  • drush fr
  • drush fra --force
  • drush fb !!!

Features Builder

  • Automatically Organizes Features
  • Rapidly Captures Changes
  • Customizable Architecture

https://www.drupal.org/project/features_builder

Why on Earth Do We Need This?

Enough with the Sales Pitch

What is it, really?

  • API for declaring builders
  • Default set of builders
  • Uses Builders to generate Feature module code

How Does Features Builder Work?

  • Builders analyze available components, provide packaging info
  • Features Builder compiles the packaging info from all Builders to form a manifest
  • Features Builder determines dependencies, puts the manifest in order
  • Features Builder passes-off the Feature writing to Features

What's a Builder?

  • Object-oriented
  • Provides a list of Features it may create
  • Computes a list of components for each Features it is creating

Core Coverage

  • Content types
  • Fields
  • File handling
  • Image presets
  • Menus
  • Site Settings
  • Search
  • Taxonomy
  • Text formats
  • Theme configs
  • Roles & permissions
  • User configs

Contrib Coverage

  • CKEditor
  • ECK
  • Feeds
  • Flag
  • Message
  • Organic Groups
  • Panels
  • Pathauto
  • Profile2
  • SearchAPI
  • Webform
  • WYSIWYG

Using Features Builder

Build Operation

drush fb [--enable] [-y]

Features Builder API

Customizing the Build

  • hook_features_builders_info()
  • hook_features_builders_info_alter()
  • hook_features_builder_components_FEATURE_alter()

Leveraging Base Classes

  • Extend FeaturesBuilderBase class
  • Identify components in setComponents() method
  • $this->components['views_view']['frontpage'] = TRUE;

FeaturesBuilderBase

  • $this->setAllComponents('node');
  • $this->setNamedComponents('node', array('article'));
  • $this->setRegexComponents('variable', '/^user_.*/');

EntityFeaturesBuilder

  • Handles field-related configuration
  • $this->setFields($entity_type, $bundle);

Final Thoughts

Shortcomings

  • UI isn't great
  • No management UI
  • Doesn't play nice with other Features
  • ???

Remaining Tasks

  • Builder coverage
  • Handbook documentation
  • Drush integration
  • API documentation
  • Test coverage

Questions

Thanks for attending.