-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoughio.profile
324 lines (290 loc) · 10 KB
/
doughio.profile
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php
/**
* Implements hook_form_alter().
*
* Allows the profile to alter the site configuration form.
*/
function doughio_form_install_configure_form_alter(&$form, $form_state) {
// Set a default name for the dev site.
$form['site_information']['site_name']['#default_value'] = t('Dough I Owe');
// Set a default country so we can benefit from it on Address Fields.
$form['server_settings']['site_default_country']['#default_value'] = 'US';
}
/**
* Implements hook_install_tasks().
*/
function doughio_install_tasks() {
$tasks = array();
// Add a page allowing the user to indicate they'd like to install demo content.
$tasks['doughio_example_store_form'] = array(
'display_name' => st('Example store'),
'type' => 'form',
);
return $tasks;
}
/**
* Task callback: returns the form allowing the user to add example store
* content on install.
*/
function doughio_example_store_form() {
drupal_set_title(st('Example store content'));
// Prepare all the options for example content.
$options = array(
'products' => st('Products'),
'product_displays' => st('Product display nodes (if <em>Products</em> is selected)'),
);
$form['example_content'] = array(
'#type' => 'checkboxes',
'#title' => st('Create example content for the following store components:'),
'#description' => st('The example content is not comprehensive but illustrates how the basic components work.'),
'#options' => $options,
'#default_value' => drupal_map_assoc(array_keys($options)),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st('Create and continue'),
'#weight' => 15,
);
return $form;
}
/**
* Submit callback: creates the requested example content.
*/
function doughio_example_store_form_submit(&$form, &$form_state) {
$example_content = $form_state['values']['example_content'];
$created_products = array();
$created_nodes = array();
// First create products if specified.
if (!empty($example_content['products'])) {
$product_names = array(
'01' => st('Product One'),
'02' => st('Product Two'),
'03' => st('Product Three')
);
foreach ($product_names as $sku => $title) {
// Create the new product.
$product = commerce_product_new('product');
$product->sku = 'PROD-' . $sku;
$product->title = $title;
$product->language = LANGUAGE_NONE;
$product->uid = 1;
// Set a default price.
$product->commerce_price[LANGUAGE_NONE][0]['amount'] = $sku * 1000;
$product->commerce_price[LANGUAGE_NONE][0]['currency_code'] = 'USD';
// Save it and retain a copy.
commerce_product_save($product);
$created_products[] = $product;
// Create a node display for the product if specified.
if (!empty($example_content['product_displays'])) {
// Create the new node.
$node = (object) array('type' => 'product_display');
node_object_prepare($node);
$node->title = $product->title;
$node->uid = 1;
// Reference the product we just made.
$node->field_product[LANGUAGE_NONE][]['product_id'] = $product->product_id;
// Make sure we set the default language
$node->language = LANGUAGE_NONE;
// Save it and retain a copy.
node_save($node);
$created_nodes[] = $node;
}
}
}
}
/**
* Creates a Catalog taxonomy vocabulary and adds a term reference field for it
* to the default product display node type.
*
* @todo This function is currently unused but should be added in as an option
* for example content creation.
*/
function _doughio_create_example_catalog() {
// Create a default Catalog vocabulary for the Product display node type.
$description = st('Describes a hierarchy for the product catalog.');
$vocabulary = (object) array(
'name' => st('Catalog'),
'description' => $description,
'machine_name' => 'catalog',
'help' => '',
);
taxonomy_vocabulary_save($vocabulary);
$field = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
'cardinality' => 1,
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'parent' => 0,
),
),
),
);
field_create_field($field);
$instance = array(
'field_name' => 'taxonomy_' . $vocabulary->machine_name,
'entity_type' => 'node',
'label' => st('Catalog category'),
'bundle' => 'product_display',
'description' => '',
'widget' => array(
'type' => 'options_select',
),
);
field_create_instance($instance);
}
/**
* Creates an image field on the specified entity bundle.
*/
function _doughio_create_product_image_field($entity_type, $bundle) {
// Add a default image field to the specified product type.
$instance = array(
'field_name' => 'field_image',
'entity_type' => $entity_type,
'label' => st('Image'),
'bundle' => $bundle,
'description' => st('Upload an image for this product.'),
'required' => FALSE,
'settings' => array(
'file_directory' => 'field/image',
'file_extensions' => 'png gif jpg jpeg',
'max_filesize' => '',
'max_resolution' => '',
'min_resolution' => '',
'alt_field' => TRUE,
'title_field' => '',
),
'widget' => array(
'type' => 'image_image',
'settings' => array(
'progress_indicator' => 'throbber',
'preview_image_style' => 'thumbnail',
),
'weight' => -1,
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => 'file'),
'weight' => -1,
),
'full' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => 'file'),
'weight' => -1,
),
'line_item' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'thumbnail', 'image_link' => ''),
'weight' => -1,
),
'node_full' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => 'file'),
'weight' => -1,
),
'node_teaser' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'thumbnail', 'image_link' => 'content'),
'weight' => -1,
),
'node_rss' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => ''),
'weight' => -1,
),
),
);
field_create_instance($instance);
}
/**
* Creates a product reference field on the specified entity bundle.
*/
function _doughio_create_product_reference($entity_type, $bundle, $field_name = 'field_product') {
// Add a product reference field to the Product display node type.
$field = array(
'field_name' => $field_name,
'type' => 'commerce_product_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'translatable' => FALSE,
);
field_create_field($field);
$instance = array(
'field_name' => $field_name,
'entity_type' => $entity_type,
'label' => st('Product'),
'bundle' => $bundle,
'description' => st('Choose the product(s) to display for sale on this node by SKU. Enter multiple SKUs using a comma separated list.'),
'required' => TRUE,
'widget' => array(
'type' => 'commerce_product_reference_autocomplete',
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'commerce_cart_add_to_cart_form',
),
'full' => array(
'label' => 'hidden',
'type' => 'commerce_cart_add_to_cart_form',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'commerce_cart_add_to_cart_form',
),
),
);
field_create_instance($instance);
}
/**
* Implements hook_update_projects_alter().
*/
function doughio_update_projects_alter(&$projects) {
// Enable update status for the Commerce Kickstart profile.
$modules = system_rebuild_module_data();
// The module object is shared in the request, so we need to clone it here.
$kickstart = clone $modules['doughio'];
$kickstart->info['hidden'] = FALSE;
_update_process_info_list($projects, array('doughio' => $kickstart), 'module', TRUE);
}
/**
* Implements hook_update_status_alter().
*
* Disable reporting of modules that are in the distribution, but only
* if they have not been updated manually. In addition, we only hide security
* issues if the distribution itself has not been updated.
*/
function doughio_update_status_alter(&$projects) {
$distribution_secure = !in_array($projects['doughio']['status'], array(UPDATE_NOT_SECURE, UPDATE_REVOKED, UPDATE_NOT_SUPPORTED));
$make_filepath = drupal_get_path('module', 'doughio') . '/drupal-org.make';
if (!file_exists($make_filepath)) {
return;
}
$make_info = drupal_parse_info_file($make_filepath);
foreach ($projects as $project_name => $project_info) {
if (!isset($project_info['info']['version']) || !isset($make_info['projects'][$project_name])) {
// Don't hide a project that is not shipped with the distribution.
continue;
}
if ($distribution_secure && in_array($project_info['status'], array(UPDATE_NOT_SECURE, UPDATE_REVOKED, UPDATE_NOT_SUPPORTED))) {
// Don't hide a project that is in a security state if the distribution
// is not in a security state.
continue;
}
$make_project_version = is_array($make_info['projects'][$project_name]) ? $make_info['projects'][$project_name]['version'] : $make_info['projects'][$project_name];
// Current version matches the version we shipped, remove it from the list.
if (DRUPAL_CORE_COMPATIBILITY . '-' . $make_project_version == $project_info['info']['version']) {
$projects['doughio']['includes'][$project_info['name']] = $project_info['info']['name'];
unset($projects[$project_name]);
}
}
}