Introducing UUID Features module

The last several projects I've worked on have all had some striking similarities. On each of these projects, we used features to export as much as we could into modules. We also built a simple install profile to enable these features at install time. Finally, we wrote an import for some (and in one case, ALL) of the existing content. These type of similarities are an instant sign that we could be doing a better job of building reusable some code.

The last several projects I've worked on have all had some striking similarities. On each of these projects, we used features to export as much as we could into modules. We also built a simple install profile to enable these features at install time. Finally, we wrote an import for some (and in one case, ALL) of the existing content. These type of similarities are an instant sign that we could be doing a better job of building reusable some code. Since we are already using features to export most of the site setup, I started to wonder how we could export some of the site content in a similar way. After investigating, several import/export type modules, I was left wanting something as simple as features. I really wanted to use features to manage this content.

The uuid module is a simple, yet powerful piece of code. It provides a UUID for several common Drupal entities that normally rely on a serial ID for uniqueness. Using UUID to identify the content to export was the missing piece of the puzzle.

The uuid features module is an implementation of the features API for nodes, vocabularies, terms and files based on the UUID's generated by the uuid module. After setting up the uuid module to automatically create UUID's for certain node types, vocabularies and files, you will have the option to add these objects to your features.

uuid_node component

The uuid_node component is responsible for exporting nodes. It provides hooks to allow other modules to interact with nodes as they are being exported and before they are imported/rebuilt. This is how taxonomy and cck fields are able to add to the export. Currently, the uuid_node component supports taxonomy and most CCK fields, with special handling for nodereference and filefield fields. Nodereferences are handled recursively, so that the referenced node will also be exported. Filefields are handled by the uuid_file component, so the entire file object is managed by features. Taxonomy terms are handled by the uuid_term component.

uuid_term component

The uuid_term component represents a taxonomy term. When a term is added, the term's vocabulary will also be added to the feature using uuid_vocabulary.

uuid_vocabulary component

The uuid_vocabulary component is the simplest of the uuid components. It simply exports and syncs the database fields for vocabulary objects.

uuid_file component

The uuid_file component is simple, except for the actual file. Since features provides no mechanism to add arbitrary files to the downloaded tar file, this becomes a two-step process, and at least at the moment, requires drush. After exporting, downloading, unpacking and enabling the feature, run

drush uuid<span class="sy0">-</span>features<span class="sy0">-</span>update<span class="sy0">-</span>files

to move the files into the module folder. This definitely needs much better documentation and some sort of warning.

And finally, a screenshot. Features | uuid demo 

Roger López