hook_product_form_alter

Definition

hook_product_form_alter(&$pform, &$node_form)
ecommerce-5--4/docs/developer/hooks/product.php, line 155

Description

Alter the node form, only if it is a product.

The benefit of using this hook over a normal form alter are:

  • product.module is better placed to determine if the node is a product
  • your code will run after product.module alterations
  • your form items will appear in a product fieldset.
  • if a site developer wants to alter the entire productized node form, then they need only make sure their form_alter runs after product form.
  • if you choose to return form items (rather than just alter the form array) then they will be placed in a product fieldset (so you don't need to worry about the structure of the form).

Parameters

$pform A product form that is being built. This should be passed by reference.

$node_form The actual node form, prior to product alteration, that can be altered as well. $node_form['#node'] contains existing values of the node.

Return value

n/a

Code

<?php
function hook_product_form_alter(&$pform, &$node_form) {
  // Example from ec_useracc_product_form_alter()
  if (product_feature_exists($node_form['#node'], 'ec_useracc') && product_feature_exists($node_form['#node'], 'ec_recurring')) {
    $pform['useracc'] = array(
      '#type' => 'fieldset',
      '#title' => t('User account provision'),
      '#weight' => -14,
      '#collapsible' => false,
      '#collapsed' => false,
    );
    $pform['useracc']['useracc_block'] = array(
      '#type' => 'checkbox',
      '#title' => t('Block the user\'s account when this product expires.'),
      '#default_value' => ($disabled ? false : $node_form['#node']->useracc['block']),
      '#description' => $desc
    );
  }
}
?>