schemaorg.features.inc in Schema.org 7
File
schemaorg.features.inc
View source
<?php
function schemaorg_features_export($data, &$export, $module_name = '') {
$export['dependencies']['rdf'] = 'rdf';
$export['dependencies']['schemaorg'] = 'schemaorg';
foreach ($data as $name) {
$parts = explode('-', $name);
$entity_type = $parts[0];
$bundle_name = $parts[1];
if ($rdf_mapping = rdf_mapping_load($entity_type, $bundle_name)) {
$export['features']['schemaorg'][$entity_type . '-' . $bundle_name] = $entity_type . '-' . $bundle_name;
}
}
return array();
}
function schemaorg_features_export_options() {
$bundles = array();
foreach (entity_get_info() as $entity_type => $entity) {
foreach ($entity['bundles'] as $bundle_name => $bundle) {
$bundles[$entity_type . '-' . $bundle_name] = $entity['label'] . ': ' . $bundle['label'];
}
}
return $bundles;
}
function schemaorg_features_export_render($module, $data, $export = NULL) {
$code = array();
$code[] = ' $schemaorg = array();';
$code[] = '';
foreach ($data as $key => $entity_type_bundle) {
if (is_array($entity_type_bundle)) {
$entity_type_bundle = $key;
}
$parts = explode('-', $entity_type_bundle);
$entity_type = $parts[0];
$bundle_name = $parts[1];
if ($rdf_mapping = rdf_mapping_load($entity_type, $bundle_name)) {
$rdf_mapping_export = features_var_export($rdf_mapping, ' ');
$rdf_bundle = features_var_export($bundle_name);
$rdf_entity_type = features_var_export($entity_type);
$code[] = " // Exported RDF mapping: {$bundle_name}";
$code[] = " \$schemaorg[{$rdf_entity_type}][{$rdf_bundle}] = {$rdf_mapping_export};";
$code[] = "";
}
}
$code[] = ' return $schemaorg;';
$code = implode("\n", $code);
return array(
'rdf_default_mappings' => $code,
);
}
function schemaorg_features_revert($module) {
return schemaorg_features_rebuild($module);
}
function schemaorg_features_rebuild($module) {
if ($defaults = features_get_default('schemaorg', $module)) {
foreach ($defaults as $entity_type => $bundles) {
foreach ($bundles as $bundle => $mapping) {
rdf_mapping_save(array(
'type' => $entity_type,
'bundle' => $bundle,
'mapping' => $mapping,
));
}
}
}
}