Skip to content

Instantly share code, notes, and snippets.

@BBGuy
Created August 8, 2016 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BBGuy/d5460d0ffa451c3d7c8ca6ee41a62ded to your computer and use it in GitHub Desktop.
Save BBGuy/d5460d0ffa451c3d7c8ca6ee41a62ded to your computer and use it in GitHub Desktop.
Create a default producr if one was not set.
/**
* Implements hook_form_alter().
*/
function dwwcommerce_form_alter(&$form, &$form_state, $form_id) {
// The style edit form.
if ($form_id == 'product_style_node_form') {
// Add a custom submit.
$form['actions']['submit']['#submit'][] = 'mymodule_node_prod_display_form_submit';
}
}
/**
* A custom submit for the product style form.
*
* Used to set the default product if not allready set.
*/
function mymodule_node_prod_display_form_submit($form, &$form_state) {
$nid = $form_state['values']['nid'];
$node = node_load($nid);
if ($node->type = 'product_style') {
if (empty($node->field_product)) {
// Add Awaiting Product.
$node->field_product[LANGUAGE_NONE][]['product_id'] = AWAITING_PRODUCT_ID;
}
node_save($node);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment