comparison sites/all/modules/features/includes/features.taxonomy.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 /**
4 * Implements hook_features_api().
5 */
6 function taxonomy_features_api() {
7 return array(
8 'taxonomy' => array(
9 'name' => t('Taxonomy'),
10 'feature_source' => TRUE,
11 'default_hook' => 'taxonomy_default_vocabularies',
12 'default_file' => FEATURES_DEFAULTS_INCLUDED,
13 ),
14 );
15 }
16
17 /**
18 * Implements hook_features_export_options().
19 */
20 function taxonomy_features_export_options() {
21 $vocabularies = array();
22 foreach (taxonomy_get_vocabularies() as $vocabulary) {
23 $vocabularies[$vocabulary->machine_name] = $vocabulary->name;
24 }
25 return $vocabularies;
26 }
27
28 /**
29 * Implements hook_features_export().
30 *
31 * @todo Test adding existing dependencies.
32 */
33 function taxonomy_features_export($data, &$export, $module_name = '') {
34 $pipe = array();
35
36 // taxonomy_default_vocabularies integration is provided by Features.
37 $export['dependencies']['features'] = 'features';
38 $export['dependencies']['taxonomy'] = 'taxonomy';
39
40 // Add dependencies for each vocabulary.
41 $map = features_get_default_map('taxonomy');
42 foreach ($data as $machine_name) {
43 if (isset($map[$machine_name]) && $map[$machine_name] != $module_name) {
44 $export['dependencies'][$map[$machine_name]] = $map[$machine_name];
45 }
46 else {
47 $export['features']['taxonomy'][$machine_name] = $machine_name;
48
49 $fields = field_info_instances('taxonomy_term', $machine_name);
50 foreach ($fields as $name => $field) {
51 $pipe['field'][] = "taxonomy_term-{$field['bundle']}-{$field['field_name']}";
52 $pipe['field_instance'][] = "taxonomy_term-{$field['bundle']}-{$field['field_name']}";
53 }
54 }
55 }
56 return $pipe;
57 }
58
59 /**
60 * Implements hook_features_export_render().
61 */
62 function taxonomy_features_export_render($module, $data) {
63 $vocabularies = taxonomy_get_vocabularies();
64 $code = array();
65 foreach ($data as $machine_name) {
66 foreach ($vocabularies as $vocabulary) {
67 if ($vocabulary->machine_name == $machine_name) {
68 // We don't want to break the entity cache, so we need to clone the
69 // vocabulary before unsetting the id.
70 $vocabulary = clone $vocabulary;
71 unset($vocabulary->vid);
72 $code[$machine_name] = $vocabulary;
73 }
74 }
75 }
76 $code = " return ". features_var_export($code, ' ') .";";
77 return array('taxonomy_default_vocabularies' => $code);
78 }
79
80 /**
81 * Implements hook_features_revert().
82 */
83 function taxonomy_features_revert($module) {
84 taxonomy_features_rebuild($module);
85 }
86
87 /**
88 * Implements hook_features_rebuild().
89 *
90 * Rebuilds Taxonomy vocabularies from code defaults.
91 */
92 function taxonomy_features_rebuild($module) {
93 if ($vocabularies = features_get_default('taxonomy', $module)) {
94 $existing = taxonomy_get_vocabularies();
95 foreach ($vocabularies as $vocabulary) {
96 $vocabulary = (object) $vocabulary;
97 foreach ($existing as $existing_vocab) {
98 if ($existing_vocab->machine_name === $vocabulary->machine_name) {
99 $vocabulary->vid = $existing_vocab->vid;
100 }
101 }
102 taxonomy_vocabulary_save($vocabulary);
103 }
104 }
105 }