You are here

function commerce_backoffice_product_form_commerce_product_ui_product_type_form_alter in Commerce Backoffice 7

Implements hook_form_FORM_ID_alter().

File

includes/commerce_backoffice_product.product_variation_types.inc, line 98
Product variation specific copy of commerce_product_ui/includes/commerce_product_ui.types.inc and commerce_product_ui/includes/commerce_product_ui.forms.inc.

Code

function commerce_backoffice_product_form_commerce_product_ui_product_type_form_alter(&$form, &$form_state) {
  $product_type = $form_state['product_type'];

  // Remove fields not used by the Inline Entity Form.
  $form['product_type']['description']['#access'] = FALSE;
  $form['product_type']['help']['#access'] = FALSE;

  // Tweak the descriptions to mention product variation types.
  $form['product_type']['name']['#description'] = t('The human-readable name of this product variation type. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.');
  if (empty($product_type['type'])) {
    $form['product_type']['type']['#description'] = t('The machine-readable name of this product variation type. This name must contain only lowercase letters, numbers, and underscores, it must be unique.');
  }
  $form['product_type']['revision']['#title'] = t('Default product variations of this type to be saved as new revisions when edited.');

  // Revisit this once Inline Entity Form gets entity_translation support.
  // If this variable is needed, it should probably reflect the
  // language_content_type_$type variable.
  if (module_exists('entity_translation')) {
    $form['product_type']['multilingual']['#type'] = 'value';
    $form['product_type']['multilingual']['#value'] = 0;
  }
  if (empty($product_type['type'])) {
    $form['create_product_display'] = array(
      '#type' => 'checkbox',
      '#title' => t('Create matching product display type'),
      '#default_value' => TRUE,
    );
  }
  $submit = $form['#submit'] = array();
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save product variation type'),
    '#submit' => array_merge($submit, array(
      'commerce_backoffice_product_variation_type_form_submit',
    )),
  );
  if (!empty($form_state['product_type']['type'])) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete product variation type'),
      '#suffix' => l(t('Cancel'), 'admin/commerce/config/product-variation-types'),
      '#submit' => array_merge($submit, array(
        'commerce_backoffice_product_variation_type_form_delete_submit',
      )),
      '#weight' => 45,
    );
  }
  else {
    $form['actions']['save_continue'] = array(
      '#type' => 'submit',
      '#value' => t('Save and add fields'),
      '#suffix' => l(t('Cancel'), 'admin/commerce/config/product-variation-types'),
      '#submit' => array_merge($submit, array(
        'commerce_backoffice_product_variation_type_form_submit',
      )),
      '#weight' => 45,
    );
  }
  return $form;
}