-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_section.features.inc
102 lines (90 loc) · 2.63 KB
/
page_section.features.inc
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
<?php
/**
* @file
* Provides the Features integration for Page Section.
*/
/**
* Implements hook_features_api().
*/
function page_section_features_api() {
return array(
'page_section' => array(
'name' => t('Page section types'),
'feature_source' => TRUE,
'default_hook' => 'page_section_type_info',
'file' => drupal_get_path('module', 'page_section') . '/page_section.features.inc',
),
);
}
/**
* Implements hook_features_export_options().
*/
function page_section_features_export_options() {
$types = page_section_type_info();
$result = array();
foreach ($types as $type => $info) {
$result[$type] = $info->label;
}
return $result;
}
/**
* Implements hook_features_export().
*/
function page_section_features_export($data, &$export, $module_name = '') {
$pipe = array();
$map = features_get_default_map('page_section');
$types = page_section_type_info();
foreach ($data as $type) {
if (!empty($types[$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.
else {
$export['features']['page_section'][$type] = $type;
$export['dependencies']['page_section'] = 'page_section';
$export['dependencies']['features'] = 'features';
}
$fields = field_info_instances('page_section', $type);
foreach ($fields as $name => $field) {
$pipe['field'][] = "page_section-{$field['bundle']}-{$field['field_name']}";
}
}
}
return $pipe;
}
/**
* Implements hook_features_export_render().
*/
function page_section_features_export_render($module, $data, $export = NULL) {
$types = page_section_type_info();
$output = array();
$output[] = ' $items = array(';
foreach ($data as $type) {
if (!empty($types[$type])) {
$output[] = " '{$type}' => array(";
$output[] = " 'label' => \"" . addslashes($types[$type]->label) . "\",";
$output[] = " ),";
}
}
$output[] = ' );';
$output[] = ' return $items;';
$output = implode("\n", $output);
return array('page_section_type_info' => $output);
}
/**
* Implements hook_features_revert().
*/
function page_section_features_revert($module = NULL) {
if ($default_types = features_get_default('page_section', $module)) {
foreach ($default_types as $type_name => $type_info) {
db_delete('page_section_type')
->condition('name', $type_name)
->execute();
}
page_section_type_info(TRUE);
menu_rebuild();
}
}