You are here

function asset_add in Asset 5.2

Present an asset submission form or a set of links to such forms.

Related topics

1 call to asset_add()
asset_wizard_add in ./asset_wizard.module
1 string reference to 'asset_add'
asset_menu in ./asset.module
Implementation of hook_menu().

File

./asset.module, line 353
Main module.

Code

function asset_add($type = NULL) {
  global $user;
  $types = asset_get_types();
  $type = isset($type) ? str_replace('-', '_', $type) : NULL;

  // If a asset type has been specified, validate its existence.
  if (isset($types[$type]) && asset_access('create', $type)) {

    // Initialize settings:
    $asset = array(
      'uid' => $user->uid,
      'type' => $type,
    );
    drupal_set_title(t('Submit @name', array(
      '@name' => $types[$type]->name,
    )));
    $output = drupal_get_form($type . '_asset_form', $asset);
  }
  else {

    // If no (valid) asset type has been provided, display a asset type overview.
    foreach ($types as $type) {
      $type_url_str = str_replace('_', '-', $type->type);
      $title = t('Add a new @s.', array(
        '@s' => $type->name,
      ));
      $out = '<dt>' . l(drupal_ucfirst($type->name), "asset/add/{$type_url_str}", array(
        'title' => $title,
      )) . '</dt>';
      $out .= '<dd>' . filter_xss_admin($type->description) . '</dd>';
      $item[$type->type] = $out;
    }
    if (isset($item)) {
      uksort($item, 'strnatcasecmp');
      $output = t('Choose the appropriate item from the list:') . '<dl>' . implode('', $item) . '</dl>';
    }
    else {
      $output = t('No asset types available.');
    }
  }
  return $output;
}