Features doesn't export correct field default value for taxonomy term reference fields.
It seems it exports the tid, while i think it would be more correct to find the term with the same name of the vocabulary with the same name.

Comments

rogical’s picture

should integrate with uuid

kurtfoster’s picture

I just manually added a function to get the tid by the machine name. The feature also uses uuid's to import the taxonomy terms, so I know the machine names in advance. The change is something like this

// Exported field_instance: 'node-bundle-field_name'
$field_instances['node-bundle-field_name'] = array(
'bundle' => 'bundle',
'default_value' => array(
0 => array(
'tid' => getTaxonomy('machine_name'),
),
),
'deleted' => 0,
'description' => '',
'display' => array(
'default' => array(
'label' => 'hidden',
'settings' => array(),
'type' => 'hidden',
'weight' => 21,
),
'teaser' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
),
... ,
... ,

So the change is just from:
'tid' => 1,
To
'tid' => function_name(),

Then my function is something like below. This could be simplified by just using taxonomy_term_load_multiple instead of getting it by the path etc, but this is a part of a larger function on my site that give me more flexibility for other purposes.

function getTaxonomy($machine_name)
// If it's in the static memory, just use that
$tid = &drupal_static(__FUNCTION__.$machine_name);
if (isset($tid)) {
return $tid;
} else {
$Tax = array();
// Try to grab an array of machine names and tid's from cache first
if ($Tax = cache_get('getTaxonomy_cache')) {
$Tax = $Tax->data;
}
else {
// Get the taxonomy vocabulary
$vocab = taxonomy_vocabulary_machine_name_load('vocab_name');
// load up all of the taxoomies within it
$taxList = taxonomy_term_load_multiple(array(), array('vid' => $vocab->vid));
// for each one, create an array of [tid] = [machine_name]. This is quite
// inefficient the first time but will be a lot quicker when it's cached
foreach ($taxList as $taxonomy) {
include_once(drupal_get_path('module', 'pathauto') . '/pathauto.inc');
$Tax[$taxonomy->tid] = pathauto_cleanstring($taxonomy->name);
}
// set the cache
cache_set('getTaxonomy_cache', $Tax, 'cache', CACHE_TEMPORARY);
}
// get the tid from the array based on the vertical machine name
$tid = array_search($vertical, $Tax);
}

if (!$tid) {
$vert = taxonomy_get_term_by_name('default_term_machine_name');
reset($vert);
$tid = $vert[key($vert)]->tid;
}
return $tid;
}

kristiaanvandeneynde’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)
Related issues: +#2158057: UUID support for default value in taxonomy term reference field settings