You are here

function webfm_form_alter in Web File Manager 5.2

Same name and namespace in other branches
  1. 5 webfm.module \webfm_form_alter()

Implementation of hook_form_alter().

File

./webfm.module, line 444

Code

function webfm_form_alter($form_id, &$form) {
  global $base_url;
  global $user;
  if ($user->uid == 1 || user_access('administer webfm') || user_access('access webfm')) {
    $access = TRUE;
  }
  else {
    $access = FALSE;
  }
  if ($form_id == 'node_type_form' && $access) {
    $form['workflow']['webfm_attach'] = array(
      '#type' => 'radios',
      '#title' => t('WebFM Attachments'),
      '#default_value' => variable_get('webfm_attach_' . $form['#node_type']->type, 0),
      '#options' => array(
        0 => t('Disabled'),
        1 => t('Enabled'),
      ),
      '#description' => t('Should this content type allow upload & file attachment via WebFM?'),
    );
  }
  if (isset($form['type'])) {
    $node = $form['#node'];
    if ($access && $form['type']['#value'] . '_node_form' == $form_id && variable_get('webfm_attach_' . $node->type, 0)) {
      $modulepath = drupal_get_path('module', 'webfm');
      drupal_add_js($modulepath . '/js/webfm.js');
      drupal_add_css($modulepath . '/css/webfm.css');
      if (is_null($inline_js)) {
        $clean_url = variable_get('clean_url', 0);
        $clean = $clean_url == 0 || $clean_url == '0' ? FALSE : TRUE;
        $inline_js = webfm_inline_js($base_url, $clean, $user->uid);
      }

      // Attachments fieldset
      $form['webfm-attach']['#theme'] = 'webfm_upload_form';
      $form['webfm-attach']['attach'] = array(
        '#type' => 'fieldset',
        '#title' => t('WebFM Attachments'),
        '#description' => t('Drag attachments to set order.<br />Changes made to the attachments are not permanent until you save this post.'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#weight' => 29,
      );
      $form['webfm-attach']['attach']['attachedfiles'] = array(
        '#prefix' => '<div id="webfm-attach">',
        '#suffix' => '</div>',
      );
      $form['webfm-attach']['attach']['attachedfiles'] += webfm_attach_attached_form($node);
      $form['webfm-attach']['attach']['browser'] = array(
        '#type' => 'fieldset',
        '#title' => t('File Browser'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $form['webfm-attach']['attach']['browser']['wrapper'] = array(
        '#type' => 'fieldset',
        '#title' => t('File Upload'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#description' => t('Uploaded file will be saved to the current directory.'),
        '#prefix' => '<div id="webfm-inline">',
        '#suffix' => '</div>',
      );
      $form['webfm-attach']['attach']['browser']['wrapper']['wrapper'] = array(
        '#prefix' => '<div id="wfmatt-wrapper">',
        '#suffix' => '</div>',
      );
      $form['webfm-attach']['attach']['browser']['wrapper']['wrapper'] += webfm_upload_form('webfm/upload');
      $form['#attributes']['enctype'] = 'multipart/form-data';
    }
  }
}