You are here

function attachment_links_form_alter in Attachment Links 6

Implementation of hook_form_alter().

Parameters

$form The form array to alter.:

$form_state The current form state.:

$form_id The ID of the form being processed.:

Return value

None.

File

./attachment_links.module, line 48
The Attachment Links module provides permanent links to files attached to a node. A single, easy-to-remember URL can be used to retrieve the preferred (canonical) or newest version of a file regardless of how many versions of that file have been…

Code

function attachment_links_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
    $desc = t('Attachments must be enabled in order for attachment links to appear.');
    $form['workflow']['attachment_links'] = array(
      '#type' => 'radios',
      '#title' => t('Attachment links'),
      '#description' => $desc,
      '#default_value' => variable_get('attachment_links_' . $form['#node_type']->type, 0),
      '#options' => array(
        t('Disabled'),
        t('Enabled'),
      ),
      '#weight' => 5,
    );
  }
  if (isset($form['type']) && isset($form['#node']) && isset($form['attachments']) && variable_get('attachment_links_' . $form['#node']->type, 0)) {
    $form['attachments']['attachment_links'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t('Attachment links'),
      '#description' => t('Attachment links provide permanent links for files attached to this node. The "preferred" version is the first file attachment listed above. Click and drag the handles to the left of each file to reorder them.'),
      '#weight' => 0,
    );

    // -- Display different help text for node creation and node editing forms.
    if ($form['nid']['#value']) {
      $form['attachments']['attachment_links']['help'] = array(
        '#value' => theme('attachment_links', $form['#node'], 'upload_form'),
      );
    }
    else {
      $form['attachments']['attachment_links']['help'] = array(
        '#value' => t('Attachment links will be created after you save the node.'),
        '#prefix' => '<div>',
        '#suffix' => '</div>',
      );
    }
  }
}