-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvih_subjects.install
109 lines (105 loc) · 3.82 KB
/
vih_subjects.install
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
<?php
/**
* @file
*/
/**
* Add panopoly featured_image field instead of the field_picture
*/
function vih_subjects_update_7000() {
$module = 'vih_subjects';
$bundle = 'subject';
$new_field_name = 'field_featured_image';
$old_field_name = 'field_picture';
// Make sure the field doesn't already exist.
if (!field_info_field($new_field_name)) {
watchdog($module, t('!field_name does not exist. You are not using Panopoly.', array('!field_name' => $new_field_name)));
// Exit. It should exist in Panopoly.
return;
}
// Create the instance.
$inst = field_info_instance('node', $new_field_name, $bundle);
if (!$inst) {
$instance = array(
'field_name' => $new_field_name,
'entity_type' => 'node',
'bundle' => $bundle,
'label' => 'Featured image',
'description' => '',
'required' => FALSE,
'settings' => array(
'alt_field' => 0,
'default_image' => 0,
'file_directory' => 'employees',
'file_extensions' => 'png jpg jpeg',
'max_filesize' => '',
'max_resolution' => '',
'min_resolution' => '400x600',
'title_field' => 0,
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'media',
'settings' => array(
'allowed_schemes' => array(
'public' => 'public',
'vimeo' => 0,
'youtube' => 0,
),
'allowed_types' => array(
'audio' => 0,
'document' => 0,
'image' => 'image',
'video' => 0,
),
'browser_plugins' => array(
'media_default--media_browser_1' => 'media_default--media_browser_1',
'media_default--media_browser_my_files' => 'media_default--media_browser_my_files',
'media_internet' => 0,
'upload' => 'upload',
'youtube' => 0,
),
'manualcrop_crop_info' => 1,
'manualcrop_default_crop_area' => 1,
'manualcrop_enable' => 1,
'manualcrop_inline_crop' => 0,
'manualcrop_instant_crop' => FALSE,
'manualcrop_instant_preview' => 1,
'manualcrop_keyboard' => 1,
'manualcrop_maximize_default_crop_area' => 0,
'manualcrop_require_cropping' => array(
'sidepicture' => 'sidepicture',
'subject_overview_thumbs' => 'subject_overview_thumbs',
),
'manualcrop_styles_list' => array(
'sidepicture' => 'sidepicture',
'subject_overview_thumbs' => 'subject_overview_thumbs',
'subject_packages_frontpage' => 'subject_packages_frontpage',
),
'manualcrop_styles_mode' => 'include',
'manualcrop_thumblist' => 1,
'progress_indicator' => 'throbber',
),
'type' => 'media_generic',
'weight' => 4,
),
);
field_create_instance($instance);
watchdog($module, t('!field_name was added successfully to !bundle', array('!field_name' => $new_field_name, '!bundle' => $bundle)));
}
$nodes = node_load_multiple(null, array('type' => $bundle));
foreach ($nodes as $nx => $no) {
if (!empty($no->{$old_field_name})) {
$no->field_featured_image = $no->{$old_field_name};
node_save($no);
$file = file_load($no->field_featured_image[LANGUAGE_NONE][0]['fid']);
if ($file) {
file_usage_add($file, $module, 'node', $no->nid);
}
}
}
$inst = field_info_instance('node', $old_field_name, $bundle);
if ($inst) {
field_delete_instance($inst, false);
}
}