function commerce_file_license_issue_by_host_form_submit in Commerce File 7
Submit callback for commerce_file_license_issue_by_host_form().
1 string reference to 'commerce_file_license_issue_by_host_form_submit'
- commerce_file_license_issue_by_host_form in includes/
commerce_file_license.forms.inc - Returns the base form array for issuing licenses on a host entity
File
- includes/
commerce_file_license.forms.inc, line 469 - Forms for creating / editing, deleting, issuing licenses
Code
function commerce_file_license_issue_by_host_form_submit($form, &$form_state) {
$issued_count = NULL;
$values =& $form_state['values'];
// normalize inputs
$license_status = isset($values['license_status']) ? $values['license_status'] : NULL;
$product_refresh = !empty($values['product_refresh']);
// exit if no entity
if (empty($form_state['entity_type']) || empty($form_state['entity'])) {
drupal_set_message(t('Licenses could not be updated or created due to an invalid form state.'), 'error');
return;
}
// extract entity info
$entity_type = $form_state['entity_type'];
$entity = $form_state['entity'];
$entity_label = $form_state['entity_label'];
// attempt to issue the licenses
$issued_count = commerce_file_license_issue_by_host_execute($entity_type, $entity, $license_status, $product_refresh);
// notify of actions performed
$msg_tokens = array(
'%label' => $entity_label ? $entity_label : entity_label($entity_type, $entity),
);
if (!empty($issued_count)) {
$message = format_plural($issued_count, 'Successfully updated 1 license for %label.', 'Successfully updated @count licenses for %label.', $msg_tokens);
drupal_set_message($message);
}
elseif (isset($issued_count) && $issued_count === 0) {
drupal_set_message(t('No licenses were updated or created for %label.', $msg_tokens));
}
else {
drupal_set_message(t('Licenses could not be updated or created for %label. Check the logs for any errors that occurred.', $msg_tokens), 'error');
}
}