-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcck.drush.inc
230 lines (209 loc) · 8.19 KB
/
cck.drush.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
function cck_drush_command() {
$items = array();
$items['cck'] = array(
'description' => "List current content types.",
'examples' => array(
'drush cck' => 'List all the content types.',
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
);
$items['cck-list'] = array(
'description' => "List current fields for a content type.",
'arguments' => array(
'content_type' => 'Content type you whose field you would like see.',
'field_name' => 'Field you would like see information about.',
),
'examples' => array(
'drush cck-list content_type' => 'List all of the CCK fields for this content type.',
'drush cck-list content_type field_name' => 'Display more detailed information about a field.',
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
);
$items['cck-add-textfield'] = array(
'description' => "Create a basic textfield for a content type.",
'arguments' => array(
'content_type' => 'Content type you would like to create field on.',
'field' => 'The field name you would like to use, add the field_ prefix.',
),
'options' => array(
'--label' => 'Human readable label.',
),
'examples' => array(
'drush cck-add-textfield content_type field_name --label="Label"' => 'Create a basic textfield on a content type with a field name and a human readable label.',
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
);
$items['cck-add-textarea'] = array(
'description' => "Create a basic textarea for a content type.",
'arguments' => array(
'content_type' => 'Content type you would like to create field on.',
'field' => 'The field name you would like to use, add the field_ prefix.',
),
'options' => array(
'--label' => 'Human readable label.',
'--rows' => 'Number of rows.',
),
'examples' => array(
'drush cck-add-textarea content_type field_name --label="Label"' => 'Create a basic textarea on a content type with a field name and a human readable label.',
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
);
$items['cck-add-optionwidgets_onoff'] = array(
'description' => "Create an on/off checkbox for a content type.",
'arguments' => array(
'content_type' => 'Content type you would like to create field on.',
'field' => 'The field name you would like to use, add the field_ prefix.',
),
'options' => array(
'--label' => 'Human readable label.',
'--allowed_values' => 'Checkbox allowed values.',
),
'examples' => array(
'drush cck-add-optionwidgets_onoff content_type field_name --label="Label" --allowed_values="true|True\nfalse|False"' => 'Create a on/off checkbox on a content type with a field name and a human readable label.',
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
);
$items['cck-delete'] = array(
'description' => "Delete a field from a content type.",
'arguments' => array(
'content_type' => 'Content type whose field you would like to delete.',
'field_names' => 'A space separated list of field you would like to delete.',
),
'examples' => array(
'drush cck-delete content_type field_name' => 'Delete this field from the content type.',
'drush cck-delete content_type field_one field_two' => 'Delete fields from the content type.',
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
);
$items['cck-add-integer'] = array(
'description' => "Create a numeric integer field for a content type.",
'arguments' => array(
'content_type' => 'Content type you would like to create field on.',
'field' => 'The field name you would like to use, add the field_ prefix.',
),
'options' => array(
'--label' => 'Human readable label.',
),
'examples' => array(
'drush cck-add-integer content_type field_name --label="Label"' => 'Create a numeric integer field on a content type with a field name and a human readable label.',
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
);
return $items;
}
function drush_drush_help($section) {
switch ($section) {
case 'drush:cck':
return dt("This command will list your content types.");
case 'drush:cck-list':
return dt("This command will list your CCK content fields for a provided content type.");
case 'drush:cck-add-textfield':
return dt("This command will add a CCK textfield.");
case 'drush:cck-add-textarea':
return dt("This command will add a CCK textarea.");
case 'drush:cck-add-optionwidgets_onoff':
return dt("This command will add a CCK on/off checkbox.");
case 'drush:cck-delete':
return dt("This command will delete CCK content fields.");
case 'drush:cck-add-decimal':
return dt("This command will add a CCK integer field.");
}
}
function drush_cck() {
$content_types = content_types();
foreach (array_keys($content_types) as $content_type) {
drush_print($content_type);
}
}
function drush_cck_list($content_type, $field_name = NULL) {
$type = content_types($content_type);
$fields = $type['fields'];
// $field_types = _content_field_types();
$info_table = array();
$info_table['content type'] = $content_type;
$info_table['field'] = $field_name;
// Maybe swap this all for a nice big table view.
if($field = $fields[$field_name]) {
$options = array('type', 'required', 'multiple');
foreach($options as $option) {
$info_table[$option] = $field[$option];
}
drush_print_table(drush_key_value_to_array_table($info_table));
}
else {
foreach (array_keys($fields) as $field) {
drush_print($field);
}
}
}
function drush_cck_add_textfield($content_type, $field_name) {
$field = array(
'field_name' => $field_name,
'type_name' => $content_type,
'type' => 'text',
'widget_type' => 'text_textfield',
);
// Look into $additional_options to do this kind of stuff and then just loop through any extra arguments.
if($label = drush_get_option('label')) {
$field['label'] = $label;
}
include_once('./'. drupal_get_path('module', 'content') .'/includes/content.crud.inc');
print_r(content_field_instance_create($field));
}
function drush_cck_add_textarea($content_type, $field_name) {
$field = array(
'field_name' => $field_name,
'type_name' => $content_type,
'type' => 'text',
'widget_type' => 'text_textarea',
);
// Look into $additional_options to do this kind of stuff and then just loop through any extra arguments.
if($label = drush_get_option('label')) {
$field['label'] = $label;
}
if($rows = drush_get_option('rows')) {
$field['rows'] = $rows;
}
include_once('./'. drupal_get_path('module', 'content') .'/includes/content.crud.inc');
print_r(content_field_instance_create($field));
}
function drush_cck_add_optionwidgets_onoff($content_type, $field_name) {
$field = array(
'field_name' => $field_name,
'type_name' => $content_type,
'type' => 'text',
'widget_type' => 'optionwidgets_onoff',
);
// Look into $additional_options to do this kind of stuff and then just loop through any extra arguments.
if($label = drush_get_option('label')) {
$field['label'] = $label;
}
if($allowed_values = drush_get_option('allowed_values')) {
$field['allowed_values'] = $allowed_values;
}
include_once('./'. drupal_get_path('module', 'content') .'/includes/content.crud.inc');
print_r(content_field_instance_create($field));
}
function drush_cck_delete($type_name) {
include_once('./'. drupal_get_path('module', 'content') .'/includes/content.crud.inc');
$fields = func_get_args();
array_shift($fields); // Remove content type name.
foreach($fields as $field_name) {
print_r(content_field_instance_delete($field_name, $type_name));
}
}
function drush_cck_add_integer($content_type, $field_name) {
$field = array(
'field_name' => $field_name,
'type_name' => $content_type,
'type' => 'number_integer',
'widget_type' => 'number',
);
// Look into $additional_options to do this kind of stuff and then just loop through any extra arguments.
if($label = drush_get_option('label')) {
$field['label'] = $label;
}
include_once('./'. drupal_get_path('module', 'content') .'/includes/content.crud.inc');
print_r(content_field_instance_create($field));
}