You are here

function asset_form in Asset 5.2

Generate the asset add/edit form array.

Related topics

1 string reference to 'asset_form'
asset_forms in ./asset.module
Implementation of hook_forms(). All asset forms share the same form handler

File

./asset.module, line 401
Main module.

Code

function asset_form($asset, $form_values = NULL) {
  global $user;
  $asset = (object) $asset;

  // Set the id of the top-level form tag
  $form['#id'] = 'asset-form';

  /**
   * Basic asset information. These elements are just values so they are not
   * even sent to the client.
   */
  foreach (array(
    'aid',
    'uid',
    'created',
    'type',
  ) as $key) {
    $form[$key] = array(
      '#type' => 'value',
      '#value' => $asset->{$key},
    );
  }

  // Changed must be sent to the client, for later overwrite error checking.
  $form['changed'] = array(
    '#type' => 'hidden',
    '#default_value' => $asset->changed,
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => check_plain($asset->title),
    '#required' => TRUE,
  );
  $form['pid'] = array(
    '#type' => 'select',
    '#title' => t('Directory'),
    '#default_value' => $asset->pid ? $asset->pid : 0,
    '#required' => TRUE,
    '#options' => asset_directory_options(),
  );
  if ($extra = asset_type_invoke($asset, 'form')) {
    $form = array_merge_recursive($form, $extra);
  }
  $form['credit'] = array(
    '#type' => 'textfield',
    '#title' => t('Credit'),
    '#default_value' => $asset->credit ? $asset->credit : '',
    '#description' => t('The credit or license of this asset.'),
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#default_value' => $asset->description ? $asset->description : '',
    '#description' => t('A short description of this module. May be used differently by different formatters.'),
    '#rows' => 3,
  );
  $form['permissions']['status'] = array(
    '#type' => 'radios',
    '#title' => t('Permissions'),
    '#description' => t('Select the permissions for this asset.  Selecting Public will allow anyone with asset permissions to use this asset.  By selecting Private, you can restrict which roles, if any, can access this asset.  If you select Private and do not select any roles, you will be the only user with access to this asset.'),
    '#required' => true,
    '#default_value' => isset($asset->status) ? $asset->status : ASSET_PUBLIC,
    '#options' => array(
      ASSET_PUBLIC => t('Public'),
      ASSET_PRIVATE => t('Private'),
    ),
  );
  $form['permissions']['roles'] = array(
    '#type' => 'checkboxes',
    '#options' => user_roles(0, 'browse assets'),
    '#default_value' => isset($asset->roles) ? $asset->roles : array(),
  );
  if (!isset($form['title']['#weight'])) {
    $form['title']['#weight'] = -5;
  }

  // If this is a new asset, fill in the default values.
  if (!isset($asset->aid)) {
    global $user;
    $asset->uid = $user->uid;
  }
  $form['#asset'] = $asset;

  // Add the buttons.
  // Allow asset_wizard a chance to theme the buttons.
  $form['buttons'] = array(
    '#tree' => FALSE,
    '#theme' => 'asset_form_buttons',
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#weight' => 45,
  );
  if ($asset->aid && asset_access('delete', $asset)) {
    $form['delete'] = array(
      '#type' => 'button',
      '#value' => t('Delete'),
      '#weight' => 50,
    );
  }
  $form['#base'] = 'asset_form';
  return $form;
}