View source
<?php
function taxonomy_configuration_api() {
return array(
'taxonomy' => array(
'name' => t('Taxonomy'),
'feature_source' => TRUE,
'default_hook' => 'taxonomy_default_vocabularies',
'default_file' => CONFIGURATION_DEFAULTS_INCLUDED,
),
);
}
function taxonomy_configuration_export_options() {
$vocabularies = array();
foreach (taxonomy_get_vocabularies() as $vocabulary) {
$vocabularies[$vocabulary->machine_name] = $vocabulary->name;
}
return $vocabularies;
}
function taxonomy_configuration_export($data, &$export, $module_name = '') {
$pipe = array();
$export['dependencies']['configuration'] = 'configuration';
$export['dependencies']['taxonomy'] = 'taxonomy';
$map = configuration_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];
}
$export['configuration']['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_configuration_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 " . configuration_var_export($code, ' ') . ";";
return array(
'taxonomy_default_vocabularies' => $code,
);
}
function taxonomy_configuration_revert($identifiers, $module_name = 'configuration') {
taxonomy_configuration_rebuild($identifiers, $module_name);
}
function taxonomy_configuration_rebuild($identifiers, $module_name = 'configuration') {
if ($vocabularies = configuration_get_default('taxonomy', $module_name)) {
$existing = taxonomy_get_vocabularies();
foreach ($vocabularies as $vocabulary) {
if (in_array($vocabulary['machine_name'], $identifiers) || !empty($identifiers) && $identifiers[0] == '#import_all') {
$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);
}
}
}
}
function configuration_check_taxonomy($identifier) {
$from_activestore =& drupal_static('configuration_from_activestore');
$component = 'taxonomy';
if (file_exists("config://configuration.taxonomy.inc")) {
include_once drupal_realpath("config://configuration.taxonomy.inc");
module_load_include('inc', 'configuration', 'configuration.export');
$code = taxonomy_configuration_export_render('configuration', array(
$identifier,
));
eval('$vocab = ' . substr(array_pop($code), 8));
$vocab_code = configuration_taxonomy_default_vocabularies();
if (empty($vocab)) {
configuration_set_status($component, $identifier, CONFIGURATION_TRACKED_DATASTORE_ONLY);
}
configuration_update_component_status($component, $identifier, $vocab, $vocab_code, $from_activestore);
}
}
function configuration_hash_taxonomy($identifier) {
module_load_include('inc', 'configuration', 'configuration.export');
$data = taxonomy_configuration_export_options();
$code = taxonomy_configuration_export_render('configuration', array(
$identifier,
));
eval('$vocab = ' . substr(array_pop($code), 8));
return md5(serialize($vocab[$identifier]));
}