features.taxonomy.inc in Features 7
File
includes/features.taxonomy.inc
View source
<?php
function taxonomy_features_api() {
return array(
'taxonomy' => array(
'name' => t('Taxonomy'),
'feature_source' => TRUE,
'default_hook' => 'taxonomy_default_vocabularies',
'default_file' => FEATURES_DEFAULTS_INCLUDED,
),
);
}
function taxonomy_features_export_options() {
$vocabularies = array();
foreach (taxonomy_get_vocabularies() as $vocabulary) {
$vocabularies[$vocabulary->machine_name] = $vocabulary->name;
}
return $vocabularies;
}
function taxonomy_features_export($data, &$export, $module_name = '') {
$pipe = array();
$export['dependencies']['features'] = 'features';
$export['dependencies']['taxonomy'] = 'taxonomy';
$map = features_get_default_map('taxonomy');
foreach ($data as $machine_name) {
if (isset($map[$machine_name]) && $map[$machine_name] != $module_name) {
$export['dependencies'][$map[$machine_name]] = $map[$machine_name];
}
else {
$export['features']['taxonomy'][$machine_name] = $machine_name;
$fields = field_info_instances('taxonomy_term', $machine_name);
foreach ($fields as $name => $field) {
$pipe['field'][] = "taxonomy_term-{$field['bundle']}-{$field['field_name']}";
}
}
}
return $pipe;
}
function taxonomy_features_export_render($module, $data) {
$vocabularies = taxonomy_get_vocabularies();
$code = array();
foreach ($data as $machine_name) {
foreach ($vocabularies as $vocabulary) {
if ($vocabulary->machine_name == $machine_name) {
$vocabulary = clone $vocabulary;
unset($vocabulary->vid);
$code[$machine_name] = $vocabulary;
}
}
}
$code = " return " . features_var_export($code, ' ') . ";";
return array(
'taxonomy_default_vocabularies' => $code,
);
}
function taxonomy_features_revert($module) {
taxonomy_features_rebuild($module);
}
function taxonomy_features_rebuild($module) {
if ($vocabularies = features_get_default('taxonomy', $module)) {
$existing = taxonomy_get_vocabularies();
foreach ($vocabularies as $vocabulary) {
$vocabulary = (object) $vocabulary;
foreach ($existing as $existing_vocab) {
if ($existing_vocab->machine_name === $vocabulary->machine_name) {
$vocabulary->vid = $existing_vocab->vid;
}
}
taxonomy_vocabulary_save($vocabulary);
}
}
}