comparison sites/all/modules/rdfx/rdfx.features.inc @ 4:ce11bbd8f642

added modules
author danieleb <danielebarchiesi@me.com>
date Thu, 19 Sep 2013 10:38:44 +0100
parents
children
comparison
equal deleted inserted replaced
3:b28be78d8160 4:ce11bbd8f642
1 <?php
2 /**
3 * Implementation of hook_features_export().
4 *
5 * Defines one or more component types that are available to Features for export
6 * and a variety of settings for each type.
7 */
8 function rdf_mappings_features_export($data, &$export, $module_name = '') {
9 // Any feature exporting RDF mappings need the rdf and rdfx modules.
10 $export['dependencies']['rdf'] = 'rdf';
11 $export['dependencies']['rdfx'] = 'rdfx';
12
13 foreach ($data as $key => $value) {
14 $parts = explode('-', $key);
15 $entity_type = $parts[0];
16 $bundle_name = $parts[1];
17
18 if ($rdf_mapping = rdf_mapping_load($entity_type, $bundle_name)) {
19 $export['features']['rdf_mappings'][$entity_type . '-' . $bundle_name] = $rdf_mapping;
20 }
21 }
22
23 return array();
24 }
25
26 /**
27 * Implementation of hook_features_export_options().
28 *
29 * Provides an array of components that can be exported for a given type.
30 */
31 function rdf_mappings_features_export_options() {
32 $bundles = array();
33
34 foreach (entity_get_info() as $entity_type => $entity) {
35 foreach ($entity['bundles'] as $bundle_name => $bundle) {
36 $bundles[$entity_type . '-' . $bundle_name] = $entity['label'] . ': ' . $bundle['label'];
37 }
38 }
39
40 return $bundles;
41 }
42
43 /**
44 * Implementation of hook_features_export_render().
45 *
46 * Renders a set of components to code as a defaults hook.
47 */
48 function rdf_mappings_features_export_render($module, $data, $export = NULL) {
49 $code = array();
50 $code[] = ' $rdf_mappings = array();';
51 $code[] = '';
52
53 foreach ($data as $key => $entity_type_bundle) {
54 if (is_array($entity_type_bundle)) {
55 $entity_type_bundle = $key;
56 }
57 $parts = explode('-', $entity_type_bundle);
58 $entity_type = $parts[0];
59 $bundle_name = $parts[1];
60 if ($rdf_mapping = rdf_mapping_load($entity_type, $bundle_name)) {
61 $rdf_mapping_export = features_var_export($rdf_mapping, ' ');
62 $rdf_bundle = features_var_export($bundle_name);
63 $rdf_entity_type = features_var_export($entity_type);
64 $code[] = " // Exported RDF mapping: {$bundle_name}";
65 $code[] = " \$rdf_mappings[$rdf_entity_type][$rdf_bundle] = $rdf_mapping_export;";
66 $code[] = "";
67 }
68 }
69
70 $code[] = ' return $rdf_mappings;';
71 $code = implode("\n", $code);
72 return array('rdf_default_mappings' => $code);
73 }
74
75 /**
76 * Implementation of hook_features_revert().
77 *
78 * Reverts components of a feature back to their default state.
79 */
80 function rdf_mappings_features_revert($module) {
81 return rdf_mappings_features_rebuild($module);
82 }
83
84 /**
85 * Implementation of hook_features_rebuild().
86 *
87 * Updates faux-exportable components back to their default state.
88 */
89 function rdf_mappings_features_rebuild($module) {
90 if ($defaults = features_get_default('rdf_mappings', $module)) {
91 foreach ($defaults as $entity_type => $bundles) {
92 foreach ($bundles as $bundle => $mapping) {
93 rdf_mapping_save(array(
94 'type' => $entity_type,
95 'bundle' => $bundle,
96 'mapping' => $mapping,
97 ));
98 }
99 }
100 }
101 }