You are here

function _itweak_upload_upload_form_prerender in iTweak Upload 6.2

Worker code for itweak_upload_form_alter(). Modify a bit the attachment fieldset, add js.

Parameters

$form['#node']->type: Node type or 'comment'.

1 string reference to '_itweak_upload_upload_form_prerender'
itweak_upload_form_alter in ./itweak_upload.module
Implementation of hook_form_alter().

File

./itweak_upload.module, line 248
iTweakUpload - Tweak attachments display and file upload forms.

Code

function _itweak_upload_upload_form_prerender($form) {
  $node_type = $form['#node']->type;
  if (isset($form['#node']->itu_comment)) {
    $node_type_name = t('comment');
    $cid = $form['cid']['#value'] ? $form['cid']['#value'] : 'new';
    $group = 'c' . $cid;
  }
  else {
    $node_type_name = strtolower(node_get_types('name', $node_type));
    $cid = NULL;
    $group = !empty($form['#node']->nid) ? $form['#node']->nid : 'new';
  }
  drupal_add_js(drupal_get_path('module', 'itweak_upload') . '/itweak_upload.js');
  $collapse = variable_get('itweak_upload_collapse_' . $node_type, 0);
  $form['attachments']['#collapsible'] = $collapse != 0;
  $form['attachments']['#collapsed'] = $collapse > 1;
  $form['attachments']['#title'] = t('Attach files to this @type', array(
    '@type' => $node_type_name,
  ));
  global $user;
  $limits = _upload_file_limits($user);
  $add_descr = ($limits['resolution'] ? t('Images are larger than %resolution will be resized. ', array(
    '%resolution' => $limits['resolution'],
  )) : '') . t('Files must be smaller than %filesize and have one of the following extensions: %extensions.', array(
    '%filesize' => format_size($limits['file_size']),
    '%extensions' => $limits['extensions'],
  ));
  if (!isset($form['attachments']['#description'])) {
    $form['attachments']['#description'] = '';
  }

  //  if (FALSE === strpos($form['attachments']['#description'], $add_descr))
  //  if (FALSE === strpos($form['attachments']['#description'], $add_descr) && variable_get('itweak_show_attachments_description', 1))
  //  if (FALSE === strpos($form['attachments']['#description'], $add_descr) && variable_get('itweak_upload_show_attachments_description', 1))
  if (FALSE === strpos($form['attachments']['#description'], $add_descr) && _itweak_upload_get_setting('show_attachments_description', '', $node_type, 1)) {
    $form['attachments']['#description'] .= ' ' . $add_descr;
  }
  $form['buttons']['#weight'] = 100;

  // Schedule theming of file attachments.
  // This method overrides themes without setting high system.weight
  // which we need low to intercept attachments delete operations.
  $form['attachments']['wrapper']['#pre_render'][] = '_itweak_upload_upload_form_prerender_themes';
  $form['attachments']['wrapper']['files']['#node_type'] = $node_type;

  // NO: separate itweak_upload_upload_preview_comment setting ??
  if (_itweak_upload_get_setting('', 'upload_preview', $node_type, 1) && is_array($form['attachments']['wrapper']['files'])) {
    $vid = !empty($form['#node']->vid) ? $form['#node']->vid : null;
    _itweak_upload_files_thumbnails($form['attachments']['wrapper']['files'], $vid, $cid, $node_type, $group);
  }
  return $form;
}