function taxonomy_xml_source_features_rebuild in Taxonomy import/export via XML 7
Same name and namespace in other branches
- 6.2 taxonomy_xml.features.inc \taxonomy_xml_source_features_rebuild()
Create/recreate the items based on the data array.
ENABLING this feature will initiate a download/reload of the defined data from the service.
Implementation of hook_features_export_rebuild().
1 call to taxonomy_xml_source_features_rebuild()
- taxonomy_xml_source_features_revert in ./
taxonomy_xml.features.inc - Implements hook_features_export_revert().
File
- ./
taxonomy_xml.features.inc, line 124
Code
function taxonomy_xml_source_features_rebuild($module) {
// Cache a note about what we have imported.
$taxonomy_xml_imports = variable_get('taxonomy_xml_imports', array());
if ($defaults = features_get_default('taxonomy_xml_source', $module)) {
foreach ($defaults as $taxonomy_xml_source_id => $settings) {
// Initiate vocab import!
drupal_set_message(t('Initiating import of !taxonomy_xml_source_id', array(
'!taxonomy_xml_source_id' => $taxonomy_xml_source_id,
)));
// Assume the target vocab name is named after the source settings.
// The values we pass through to the import format are copied straight
// from the settings array the feature provides.
$values = $settings;
// Create the vocab if neccessary.
// Any additional values (description etc) for the vocab may be set from
// the settings array.
// If it already exists, the placeholder will be the pre-existing vocab
// by that name. (text name, not machine ID yet).
// Overload the 'module' value to provide a machine_name.
// This may be used by features
// (NOT features_extra, which does it in its own table)
if (empty($settings['module'])) {
// Setting this will help integrate with features?
$settings['module'] = 'features_' . preg_replace('/[^a-zA-Z0-9]+/', '_', $taxonomy_xml_source_id);
}
if (empty($settings['name'])) {
// Should not happen.
$settings['name'] = $taxonomy_xml_source_id;
}
if (empty($settings['nodes'])) {
$settings['nodes'] = array();
}
// We allow a special wildcard value for the 'nodes' array.
if (is_string($settings['nodes']) && $settings['nodes'] == '*') {
$settings['nodes'] = array_map('check_plain', node_get_types('names'));
}
$vocabulary = _taxonomy_xml_get_vocabulary_placeholder($settings['name'], $settings);
$values['vid'] = $vocabulary->vid;
// If trying to deploy a taxonomy file with a features module, you can use
// the token %module in the filepath setting.
// Replace that now.
if (isset($values['filepath'])) {
$values['filepath'] = strtr($values['filepath'], array(
'!module' => drupal_get_path('module', $module),
));
}
// Taxonomy_xml features exports can be either a 'service'
// Using the format seen in lookup_services.inc
if (isset($settings['servicetype'])) {
taxonomy_xml_invoke_service_request($settings, $values);
}
else {
// Or the feature may be a macro-like array, containing form values
// that would be submitted to the import form.
taxonomy_xml_fetch_and_import($values);
}
$taxonomy_xml_imports[$taxonomy_xml_source_id] = $settings;
}
variable_set('taxonomy_xml_imports', $taxonomy_xml_imports);
}
else {
drupal_set_message(t('No taxonomy sources to install for %module', array(
'%module' => $module,
)), 'error');
}
}