function uc_file_feature_form in Ubercart 5
Same name and namespace in other branches
- 6.2 uc_file/uc_file.module \uc_file_feature_form()
- 7.3 uc_file/uc_file.module \uc_file_feature_form()
Form builder for hook_product_feature
1 string reference to 'uc_file_feature_form'
- uc_file_product_feature in uc_file/
uc_file.module - Implementation of hook_product_feature().
File
- uc_file/
uc_file.module, line 337 - Allows products to be associated with downloadable files.
Code
function uc_file_feature_form($node, $feature) {
if (!is_dir(variable_get('uc_file_base_dir', NULL))) {
drupal_set_message(t('A file directory needs to be configured in <a href="!url">product feature settings</a> before a file can be selected.', array(
'!url' => url('admin/store/settings/products/edit/features'),
)), 'error');
}
_file_table_action('insert');
$models = !_get_adjustment_models($node->nid) ? array(
NULL => t('Any'),
$node->model => $node->model,
) : array(
NULL => t('Any'),
$node->model => $node->model,
) + _get_adjustment_models($node->nid);
if (!empty($feature)) {
$file_product = db_fetch_object(db_query("SELECT * FROM {uc_file_products} as p LEFT JOIN {uc_files} as f ON p.fid = f.fid WHERE pfid = %d", $feature['pfid']));
$default_feature = $feature['pfid'];
$default_model = $file_product->model;
$default_filename = $file_product->filename;
$default_description = $file_product->description;
$default_shippable = $file_product->shippable;
}
else {
$default_shippable = $node->shippable;
}
$form['nid'] = array(
'#type' => 'value',
'#value' => $node->nid,
);
$form['pfid'] = array(
'#type' => 'value',
'#value' => $default_feature,
);
$form['uc_file_model'] = array(
'#type' => 'select',
'#title' => t('Model/SKU'),
'#default_value' => $default_model,
'#description' => t('This is the model/SKU that will need to be purchased to obtain the file download.'),
'#options' => $models,
);
$form['uc_file_filename'] = array(
'#type' => 'textfield',
'#title' => t('File download'),
'#default_value' => $default_filename,
'#autocomplete_path' => '_autocomplete_file',
'#description' => t('The file that can be downloaded when product is purchased (enter a path relative to the %dir directory).', array(
'%dir' => variable_get('uc_file_base_dir', NULL),
)),
'#maxlength' => 255,
);
$form['uc_file_description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#default_value' => $default_description,
'#maxlength' => 255,
'#description' => t('A description of the download associated with the product.'),
);
$form['uc_file_shippable'] = array(
'#type' => 'checkbox',
'#title' => t('Shippable product'),
'#default_value' => $default_shippable,
'#description' => t('Check if this product model/SKU file download is also associated with a shippable product.'),
);
return uc_product_feature_form($form);
}