function commerce_pado_form_alter in Commerce Product Add-on 7
File
- ./
commerce_pado.module, line 13 - Commerce Product Add On adds an option to entityreference fields that allows selected products to act as "add-ons" for the parent product.
Code
function commerce_pado_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'field_ui_field_edit_form') {
/*
* Only add the option if this instance is attached to a Commerce Product
* entity, and the field is of type 'entityreference.'
*/
if (isset($form['#instance']) && $form['#instance']['entity_type'] == 'commerce_product' && ($form['#field']['type'] == 'entityreference' || $form['#field']['type'] == 'commerce_product_reference')) {
$form['commerce_pado_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Commerce Product Add On Settings'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => -1,
);
$commerce_pado_settings = variable_get('commerce_pado_settings', array());
$instance_id = $form['#instance']['id'];
$form['commerce_pado_settings']['commerce_pado_on'] = array(
'#type' => 'checkbox',
'#title' => t('Offer products referenced with this field as add-on products on the Add to Cart form.'),
'#description' => t('Each product referenced will be displayed next to a
checkbox on the Add to Cart form. You can control how
a product is displayed by the editing Add-on view in
the display settings of the product entity. If selected,
the target type must be set to <strong>Commerce Product</strong>.'),
'#default_value' => isset($commerce_pado_settings[$instance_id]) ? $commerce_pado_settings[$instance_id] : 0,
);
$form['#submit'][] = 'commerce_pado_field_settings_submit';
$form['#validate'][] = 'commerce_pado_field_settings_validate';
}
}
}