features.node.inc
4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* Implements hook_features_api().
*/
function node_features_api() {
return array(
'node' => array(
'name' => t('Content types'),
'feature_source' => TRUE,
'default_hook' => 'node_info',
'alter_type' => FEATURES_ALTER_TYPE_INLINE,
),
);
}
/**
* Implements hook_features_export_options().
*/
function node_features_export_options() {
return node_type_get_names();
}
/**
* Implements hook_features_export.
*/
function node_features_export($data, &$export, $module_name = '') {
$pipe = array();
$map = features_get_default_map('node');
foreach ($data as $type) {
// Poll node module to determine who provides the node type.
if ($info = node_type_get_type($type)) {
// If this node type is provided by a different module, add it as a dependency
if (isset($map[$type]) && $map[$type] != $module_name) {
$export['dependencies'][$map[$type]] = $map[$type];
}
// Otherwise export the node type.
elseif (in_array($info->base, array('node_content', 'features'))) {
$export['features']['node'][$type] = $type;
$export['dependencies']['node'] = 'node';
$export['dependencies']['features'] = 'features';
}
$fields = field_info_instances('node', $type);
foreach ($fields as $name => $field) {
$pipe['field_instance'][] = "node-{$field['bundle']}-{$field['field_name']}";
}
}
}
return $pipe;
}
/**
* Implements hook_features_export_render().
*/
function node_features_export_render($module, $data, $export = NULL) {
$elements = array(
'name' => TRUE,
'base' => FALSE,
'description' => TRUE,
'has_title' => FALSE,
'title_label' => TRUE,
'help' => TRUE,
);
$output = array();
$output[] = ' $items = array(';
foreach ($data as $type) {
if ($info = node_type_get_type($type)) {
// Force module name to be 'features' if set to 'node. If we leave as
// 'node' the content type will be assumed to be database-stored by
// the node module.
$info->base = ($info->base === 'node') ? 'features' : $info->base;
$output[] = " '{$type}' => array(";
foreach ($elements as $key => $t) {
if ($t) {
$text = str_replace("'", "\'", $info->$key);
$text = !empty($text) ? "t('{$text}')" : "''";
$output[] = " '{$key}' => {$text},";
}
else {
$output[] = " '{$key}' => '{$info->$key}',";
}
}
$output[] = " ),";
}
}
$output[] = ' );';
$output[] = ' drupal_alter(\'node_info\', $items);';
$output[] = ' return $items;';
$output = implode("\n", $output);
return array('node_info' => $output);
}
/**
* Implements hook_features_revert().
*
* @param $module
* name of module to revert content for
*/
function node_features_revert($module = NULL) {
if ($default_types = features_get_default('node', $module)) {
foreach ($default_types as $type_name => $type_info) {
// Delete node types
// We don't use node_type_delete() because we do not actually
// want to delete the node type (and invoke hook_node_type()).
// This can lead to bad consequences like CCK deleting field
// storage in the DB.
db_delete('node_type')
->condition('type', $type_name)
->execute();
}
node_types_rebuild();
menu_rebuild();
}
}
/**
* Implements hook_features_disable().
*
* When a features module is disabled, modify any node types it provides so
* they can be deleted manually through the content types UI.
*
* @param $module
* Name of module that has been disabled.
*/
function node_features_disable($module) {
if ($default_types = features_get_default('node', $module)) {
foreach ($default_types as $type_name => $type_info) {
$type_info = node_type_load($type_name);
$type_info->module = 'node';
$type_info->custom = 1;
$type_info->modified = 1;
$type_info->locked = 0;
node_type_save($type_info);
}
}
}
/**
* Implements hook_features_enable().
*
* When a features module is enabled, modify any node types it provides so
* they can no longer be deleted manually through the content types UI.
*
* @param $module
* Name of module that has been enabled.
*/
function node_features_enable($module) {
if ($default_types = features_get_default('node', $module)) {
foreach ($default_types as $type_name => $type_info) {
// Ensure the type exists.
if ($type_info = node_type_load($type_name)) {
$type_info->module = $module;
$type_info->custom = 0;
$type_info->modified = 0;
$type_info->locked = 1;
node_type_save($type_info);
}
}
}
}