function uc_product_form_node_type_form_alter in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_product/uc_product.module \uc_product_form_node_type_form_alter()
- 6.2 uc_product/uc_product.module \uc_product_form_node_type_form_alter()
Implements hook_form_FORM_ID_alter().
Adds a default image field setting to product content types.
File
- uc_product/
uc_product.module, line 876 - The product module for Ubercart.
Code
function uc_product_form_node_type_form_alter(&$form, &$form_state) {
$type = $form['#node_type'];
if (!uc_product_is_product($type->type)) {
return;
}
$form['uc_product'] = array(
'#type' => 'fieldset',
'#title' => t('Ubercart product settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(
'vertical-tabs' => drupal_get_path('module', 'uc_product') . '/uc_product.js',
),
),
);
// Shippable.
$form['uc_product']['uc_product_shippable'] = array(
'#type' => 'checkbox',
'#title' => t('Product and its derivatives are shippable.'),
'#default_value' => variable_get('uc_product_shippable_' . $type->type, 1),
'#description' => t('This setting can still be overridden on the node form.'),
'#return_value' => 1,
'#weight' => -5,
);
// Image field.
$instances = field_info_instances('node', $type->type);
$options = array(
'' => t('None'),
);
foreach ($instances as $field_name => $instance) {
if (strpos($instance['widget']['type'], 'image') !== FALSE || $instance['widget']['type'] == 'media_generic' && isset($instance['widget']['settings']['allowed_types']) && $instance['widget']['settings']['allowed_types'] == array(
'image' => 'image',
)) {
$options[$field_name] = $instance['label'];
}
}
$form['uc_product']['uc_image'] = array(
'#type' => 'select',
'#title' => t('Product image field'),
'#default_value' => variable_get('uc_image_' . $type->type, NULL),
'#options' => $options,
'#description' => t('The selected field will be used on Ubercart pages to represent the products of this content type.'),
'#weight' => -4,
);
}