-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfe_profile.module
More file actions
97 lines (83 loc) · 2.45 KB
/
fe_profile.module
File metadata and controls
97 lines (83 loc) · 2.45 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
<?php
/**
* Implementation of hook_features_api().
*/
function fe_profile_features_api() {
return array(
'fe_profile' => array(
'name' => t('Profile fields'),
'feature_source' => TRUE,
'default_hook' => 'fe_profile_export_fields',
'default_file' => FEATURES_DEFAULTS_INCLUDED_COMMON,
)
);
}
/**
* Implementation of hook_features_export_options().
*/
function fe_profile_features_export_options() {
$options = array();
$table = 'profile_field';
$query = "SELECT * FROM {{$table}}";
$fields = db_query($query);
while ($row = $fields->fetchObject()) {
$options[$row->name] = $row->name;
}
return $options;
}
/**
* Implementation of hook_features_export().
*/
function fe_profile_features_export($data, &$export, $module_name = '') {
$export['dependencies']['profile'] = 'profile';
foreach ($data as $machine_name) {
$export['features']['fe_profile'][$machine_name] = $machine_name;
}
return array();
}
/**
* Implementation of hook_features_export_render().
*/
function fe_profile_features_export_render($module_name, $data) {
$items = array();
$table = 'profile_field';
foreach ($data as $key) {
$field = db_query("SELECT * FROM {{$table}} WHERE name = :profile_field_name", array(':profile_field_name' => $key))->fetchObject();
$items[$key] = $field;
}
$code = " \$items = " . features_var_export($items, ' ') . ";\n";
$code .= ' return $items;';
return array('fe_profile_export_fields' => $code);
}
/**
* Implementation of hook_features_revert().
*/
function fe_profile_features_revert($module) {
$table = 'profile_field';
$defaults = features_get_default('fe_profile', $module);
// Revert.
foreach ($defaults as $object) {
_fe_profile_save_field($object);
}
}
function _fe_profile_save_field($field_data) {
if (!isset($field_data['options'])) {
$field_data['options'] = '';
}
if (!isset($field_data['page'])) {
$field_data['page'] = '';
}
if (!isset($field_data['fid'])) {
$field_data = (object)$field_data;
drupal_write_record('profile_field', $field_data);
}
else {
$field_data = (object)$field_data;
if(!db_query("SELECT * FROM {profile_field} WHERE fid = :fid", array(':fid' => $field_data->fid))->fetchObject() ) {
drupal_write_record('profile_field', $field_data);
}
else {
drupal_write_record('profile_field', $field_data, array('fid'));
}
}
}