Wednesday, August 03, 2011

Managing optional features in a Drupal Distro

So you need to build a comprehensive distro using features to export data into code. Fair enough. What could be one of the most common problems in trying to create a common solution for all sites?

Problems:
  1. 20% of the sites would want additional fields

    In your distro, say content type 'article' has 10 fields and needs 2 optional fields. All sites will use the 10 'core' fields and the 2 optional fields may or may not be used.

  2. Some sites want to alter field labels and change display settings on content types

Solutions:

  1. Separate overridable feature for extra fields per content type

    Export the main content with 10 fields into one feature and the optional fields into another feature. Site builders can leave the main feature alone and modify the extra feature only (change field permissions, usage, labels etc.)

    Perhaps its not easy to export the content type with the extra fields left out. In that case, manually remove the field's references from the export files. Usually those will be in *.features.field.inc & *.info files.

    Then export the extra fields in a separate content type and manually add a dependency to the main feature.

  2. template_preprocess hooks.

    Consider encouraging site-builders to place all field alterations in appropriate hooks such as hook_form_alter() and hook_template_preprocess_page()

  3. Override field display settings

    This module is still in its infancy but its possible to export field display settings separately into a feature. A comprehensive guide can be found here - http://www.agileapproach.com/blog-entry/new-paradigm-overriding-drupal-features