function commerce_product_reference_form_field_ui_display_overview_form_alter in Commerce Core 7
Implements hook_form_FORM_ID_alter().
Override the field manage display screen to add a description to the fields we embed into the target node from the product. Also implements the same hack we had to use in commerce_product_reference_field_extra_fields_display_alter() to default product extra fields to be hidden.
File
- modules/
product_reference/ commerce_product_reference.module, line 183 - Defines a field type for referencing products from other entities.
Code
function commerce_product_reference_form_field_ui_display_overview_form_alter(&$form, &$form_state) {
if (!module_exists('commerce_product_ui')) {
return;
}
$entity_type = $form['#entity_type'];
$bundle = $form['#bundle'];
$view_mode = $form['#view_mode'];
// Load the bundle settings for the current bundle.
$bundle_settings = field_bundle_settings($entity_type, $bundle);
// Loop over the extra fields defined by the Product Reference module for this
// entity to set help text and make sure any extra field derived from product
// fields to be hidden by default.
$product_fields = commerce_product_reference_field_extra_fields();
if (isset($product_fields[$entity_type][$bundle])) {
foreach ($product_fields[$entity_type][$bundle]['display'] as $field_name => $field) {
// If the extra field has configurable settings, add a help text for it.
if (!empty($field['configurable'])) {
$form['fields'][$field_name]['format']['type']['#description'] = t('Modify the settings for this field on the <a href="!url">product type "manage display" configuration</a>.', array(
'!url' => url('admin/commerce/products/types'),
));
}
else {
// Otherwise just mention it as visibility settings.
$form['fields'][$field_name]['format']['type']['#description'] = t('The visibility of this field may also need to be toggled in the <a href="!url">product type "manage display" configuration</a>.', array(
'!url' => url('admin/commerce/products/types'),
));
// If no data yet exists for the extra field in the bundle settings...
if (empty($bundle_settings['extra_fields']['display'][$field_name]) || empty($bundle_settings['view_modes'][$view_mode]['custom_settings']) && empty($bundle_settings['extra_fields']['display'][$field_name]['default']) || !empty($bundle_settings['view_modes'][$view_mode]['custom_settings']) && empty($bundle_settings['extra_fields']['display'][$field_name][$view_mode])) {
// Default it to be hidden.
$form['fields'][$field_name]['format']['type']['#default_value'] = 'hidden';
}
}
}
}
}