You are here

function commerce_file_license_issue_by_host_form in Commerce File 7

Returns the base form array for issuing licenses on a host entity

1 string reference to 'commerce_file_license_issue_by_host_form'
commerce_file_forms in ./commerce_file.module
Implements hook_forms().

File

includes/commerce_file_license.forms.inc, line 413
Forms for creating / editing, deleting, issuing licenses

Code

function commerce_file_license_issue_by_host_form($form, &$form_state, $entity_type, $entity) {
  global $user;

  // Add access to entire form
  // @todo: check create also?
  $form['#access'] = commerce_file_license_admin_access('update', $user);

  // Ensure this include file is loaded when the form is rebuilt from the cache.
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'commerce_file') . '/includes/commerce_file_license.forms.inc';

  // store the order object
  $form_state['entity_type'] = $entity_type;
  $form_state['entity'] = $entity;
  $form_state['entity_label'] = entity_label($entity_type, $entity);

  // set default status
  $default_status = NULL;
  $allowed_statuses = commerce_file_license_statuses(array(
    'state' => 'allowed',
  ));
  if (!empty($allowed_statuses)) {
    $default_status = key($allowed_statuses);
  }
  else {
    $default_status = commerce_file_license_status_default('name');
  }

  // build form elements
  $form['license_status'] = array(
    '#type' => 'select',
    '#title' => t('License status'),
    '#default_value' => $default_status,
    '#options' => commerce_file_license_status_options_list(),
    '#required' => TRUE,
  );
  $form['product_refresh'] = array(
    '#type' => 'checkbox',
    '#title' => t('Sync to current product'),
    '#description' => t('Enabling this will update the as-purchased snapshot of the files on the line items with the current product files and access limits.'),
    '#default_value' => FALSE,
  );

  // Add actions
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
    '#weight' => 40,
  );
  $form['#submit'][] = 'commerce_file_license_issue_by_host_form_submit';
  return $form;
}