Using UUID and UUID_FEATURES modules Part 2
Posted on: Friday, January 27th 2012 by Keen

Last time I posted a blog: "Using UUID and UUID_FEATURES modules Part 1" where I explained the basics of using UUID module to generate identity values.
The next thing you'll want to do is to use it in the real feature export components. Here is an example how we use it:
One of the projects I was working on needed locale languages support in taxonomy terms. Unfortunately, the exportable taxonomy component uuid_term provided by uuid_features module does not support i18n and is not exporting language & translation set fields.

The way these two fields are stored in the database are:

Language Code of taxonomy term

Table: term_date
Field: language

Translation set ID is a group id that linked translated
taxonomy terms together, generated by i18ntaxonomy_next_trid()

Table: term_data
Field: trid

For more information, please check out i18n module.

And here are the steps to make them exportable with taxonomy terms:

Step 1:

Include uuid table definition for trid field in uuid_features.install

/**
* Implementation of hook_schema().
*/
function uuid_features_schema() {
return array(
'uuid_i18ntrid' => uuid_table_schema('i18ntrid', 'trid'),
);
}

Step 2:

Update uuid_term_features_export_render () function in includes/uuid_term.features.inc
Add language code and trid fields to export.

Replace these lines:

// Whitelist of term properties.
$props = array('name', 'description', 'weight');
foreach ($props as $key) {
if (isset($term->$key)) {
$export[$key] = $term->$key;
}
}

By:
// Whitelist of term properties.
// add language and trid fields to export
$props = array('name', 'description', 'weight', 'language', 'trid');
foreach ($props as $key) {
if (isset($term->$key)) {
$export[$key] = $term->$key;
}
}
if((int)$export['trid'] > 0) {
//if trid field is not empty, replace it with trid_uuid
$export['trid_uuid'] = uuid_get_uuid('i18ntrid', 'trid', (int)$export['trid']);
//if trid _uuid value not yet exists, generate a new one by using uuid_set_uuid()
if(!$export['trid_uuid']) {
$export['trid_uuid'] = uuid_set_uuid('i18ntrid', 'trid', $export['trid']);
}
}
unset($export['trid']);

Step 3:

Update uuid_term_features_export_rebuild () function in includes/uuid_term.features.inc
We will translate trid_uuid back to trid by uuid_get_serial_id() and i18ntaxonomy_next_trid()

Search this line in uuid_term_features_export_rebuild()

$ret = taxonomy_save_term($data);

And insert following codes before this line:

//process trid field
if($data['trid_uuid']) {
//try to get trid by trid_uuid
$data['trid'] = uuid_get_serial_id('i18ntrid', 'trid', $data['trid_uuid']);
//if trid does not yet exist, generate a new trid by i18ntaxonomy_next_trid()
//and set its uuid by trid_uuid
if((int)$data['trid'] == 0) {
$data['trid'] = i18ntaxonomy_next_trid();
uuid_set_uuid('i18ntrid', 'trid', (int)$data['trid'], $data['trid_uuid']);
}
unset($data['trid_uuid']);
}
else {
$data['trid'] = 0;
}

Now if you recreate those features containing taxonomy terms. You will get language and translation set fields exported correctly.

Modifying a contributed module itself is not suggested, and the modification made here is just for demonstration. You may clone the uuid_term component and modify it for your needs to create your own features integration module.

Thanks for reading.

Post new comment

The content of this field is kept private and will not be shown publicly.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.