diff --git a/commerce_backoffice_product.module b/commerce_backoffice_product.module index 9a8dad9..c437c65 100644 --- a/commerce_backoffice_product.module +++ b/commerce_backoffice_product.module @@ -230,6 +230,23 @@ function theme_commerce_backoffice_product_node_add_list($variables) { } /** + * Implements hook_form_field_ui_field_edit_form_alter(). + * For extra field instance settings. + */ +function commerce_backoffice_product_form_field_ui_field_edit_form_alter(&$form) { + // For term reference fields of Product displays Only. + if ($form['#field']['type'] == 'taxonomy_term_reference' && in_array($form['#instance']['bundle'], array_keys(commerce_product_reference_node_types()))) { + $field = $form['#field']; + $form['instance']['not_product_catalog'] = array( + '#type' => 'checkbox', + '#title' => t('Not a product catalog?'), + '#default_value' => empty($form['#instance']['not_product_catalog']) ? 0 : 1, + '#description' => t('For term reference fields that should not be in the Product catalog Vertical tab.'), + ); + } +} + +/** * Implements hook_form_views_form_alter(). */ function commerce_backoffice_product_form_alter(&$form, &$form_state, $form_id) { @@ -237,26 +254,29 @@ function commerce_backoffice_product_form_alter(&$form, &$form_state, $form_id) if (isset($form['#node_edit_form'])) { $product_node_types = commerce_product_reference_node_types(); if (in_array($form['#node']->type, array_keys($product_node_types))) { - // Enable the #fieldset key. - $form['#pre_render'][] = 'commerce_backoffice_pre_render_add_fieldset_markup'; - // Add a new vertical tab. - $form['product_catalog'] = array( - '#type' => 'fieldset', - '#title' => t('Product catalog'), - '#group' => 'additional_settings', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => -10, - ); - + $product_catalog_tab = FALSE; // Assign all taxonomy reference fields to the new vertical tab. foreach (field_info_instances('node', $form['#node']->type) as $field_name => $instance) { $field = field_info_field($field_name); - if ($field['type'] == 'taxonomy_term_reference') { + if ($field['type'] == 'taxonomy_term_reference' && (!isset($instance['not_product_catalog']) || !$instance['not_product_catalog'])) { + $product_catalog_tab = TRUE; $form[$field_name]['#fieldset'] = 'product_catalog'; } } + if ($product_catalog_tab) { + // Enable the #fieldset key. + $form['#pre_render'][] = 'commerce_backoffice_pre_render_add_fieldset_markup'; + // Add a new vertical tab. + $form['product_catalog'] = array( + '#type' => 'fieldset', + '#title' => t('Product catalog'), + '#group' => 'additional_settings', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#weight' => -10, + ); + } } } // Alter the Exposed Filters for products page