function itweak_upload_upload_form_current in iTweak Upload 6.2
Implementation of theme_upload_form_current(). Theme the upload form for current attachments.
2 string references to 'itweak_upload_upload_form_current'
- itweak_upload_theme in ./
itweak_upload.module - Implementation of hook_theme().
- _itweak_upload_upload_form_prerender_themes in ./
itweak_upload.module - Worker code for itweak_upload_form_alter(). Add custom themes.
File
- ./
itweak_upload.module, line 705 - iTweakUpload - Tweak attachments display and file upload forms.
Code
function itweak_upload_upload_form_current($form) {
drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
$node_type = isset($form['#node_type']) ? $form['#node_type'] : 'default';
// Insert
if (ITU_USE_INSERT_MODULE && module_exists('insert')) {
$widget = _itweak_upload_get_insert_widget_settings($node_type);
$widget['class'] = isset($widget['insert_class']) ? $widget['insert_class'] . ' ' : '';
// save for mime-ext
}
$rows = array();
foreach (element_children($form) as $key) {
// Add the extension as a class for styling
$extension = strtolower(substr(strrchr($form[$key]['filename']['#value'], '.'), 1));
if ($widget) {
static $js_added;
if (!isset($js_added)) {
$js_added = array();
drupal_add_js(drupal_get_path('module', 'insert') . '/insert.js');
drupal_add_js(drupal_get_path('module', 'itweak_upload') . '/itweak_upload.insert.js');
$insert_settings = array(
'maxWidth' => $widget['insert_width'],
'wrapper' => 'tr',
'fields' => array(
// FIXME: alt and title...
'alt' => 'input[name$="[alt]"], textarea[name$="[alt]"]',
'title' => 'input[name$="[title]"], textarea[name$="[title]"]',
'description' => 'input[name$="[description]"], textarea[name$="[description]"]',
),
);
}
if (!isset($js_added[$widget['type']])) {
$js_added[$widget['type']] = TRUE;
drupal_add_js(array(
'itweak_upload' => array(
'widgets' => array(
$widget['type'] => $insert_settings,
),
),
), 'setting');
}
$insert_styles = array_filter((array) $widget['insert_styles']);
$default = !empty($widget['insert_default']) ? $widget['insert_default'] : 'auto';
if (!isset($insert_styles[$default])) {
$insert_styles[$default] = $default;
}
$element =& $form[$key];
// For insert.module code copy-paste
$item = array(
'filepath' => $form[$key]['filepath']['#value'],
'filename' => $form[$key]['filename']['#value'],
);
// Build a pretend item - we need only filepath
$style_options = array();
// BEGIN code reuse (original indent) from insert.module.
// call points are:
// - insert_style_load()
// - insert_content()
// - theme_insert_widget()
foreach ($insert_styles as $style_name => $enabled) {
if (is_integer($style_name)) {
$style_name = $enabled;
$enabled = TRUE;
}
// Patch for D6 Form API
if ($enabled && ($style = insert_style_load($style_name))) {
$widget['insert_class'] = $widget['class'] . 'mime-' . $extension;
$element['insert_templates'][$style_name] = array(
'#type' => 'hidden',
'#value' => insert_content($item, $style, $widget),
'#id' => $element['#id'] . '-insert-template-' . str_replace('_', '-', $style_name),
'#name' => $element['#name'] . '[insert_template][' . $style_name . ']',
'#attributes' => array(
'class' => 'insert-template',
),
);
$style_options[$style_name] = $style['label'];
}
}
$element['insert'] = array(
'#theme' => 'insert_widget',
'#type' => 'markup',
'#options' => $style_options,
'#widget' => $widget,
'#weight' => -1,
'#default_value' => $default,
);
// END code reuse.
// theme_insert_widget() comes with its own .insert-button - we will remove it in JS
}
// COLUMN - Add class to group weight fields for drag and drop.
$form[$key]['weight']['#attributes']['class'] = 'upload-weight';
$row = array(
'',
);
// COLUMN - icon or preview
if (isset($form[$key]['preview']) && is_array($form[$key]['preview'])) {
// this td will be showing preview thumbnail
$row[] = array(
'data' => drupal_render($form[$key]['preview']),
'class' => 'mime',
);
}
else {
// this td will be used for mime icon (CSS)
$row[] = array(
'data' => '',
'class' => 'mime',
);
}
// COLUMN - file descritpion, size & URL, plus js-injected rename/remove links
$html = '';
// Description: we save the URL, remove it as a description and change the size of the input
$url = $form[$key]['description']['#description'];
unset($form[$key]['description']['#description']);
$form[$key]['description']['#size'] = 40;
$form[$key]['description']['#attributes'] = array(
'class' => 'rename',
);
$html .= drupal_render($form[$key]['description']);
// Size & URL
$html .= '<span class="details">' . drupal_render($form[$key]['size']) . ' - ' . $url . '</span>';
$row[] = array(
'data' => $html,
'class' => 'file container-inline',
);
// COLUMN - insert link & selector
if ($widget) {
$html = drupal_render($form[$key]['insert_templates']);
$html .= drupal_render($form[$key]['insert']);
// Add span same as in .file - this is to help for vertical alignment
$html .= '<span class="details">' . ' ' . '</span>';
$row[] = array(
'data' => $html,
'class' => 'itu-insert container-inline',
);
}
// COLUMN - Remove checkbox (hidden by JS)
$form[$key]['remove']['#attributes'] = array(
'class' => 'itu-remove',
);
$form[$key]['remove']['#suffix'] = ' ' . t('Remove');
$row[] = array(
'data' => drupal_render($form[$key]['remove']),
'class' => 'itu-remove container-inline',
);
// COLUMN - List checkbox & (optional) private checkbox
$form[$key]['list']['#suffix'] = ' ' . t('List');
$html = drupal_render($form[$key]['list']);
// Handle private checkbox (from private_upload.module)
if (isset($form[$key]['private'])) {
$form[$key]['private']['#suffix'] = ' ' . t('Private');
$html .= ' ' . drupal_render($form[$key]['private']);
}
// Add span same as in .file - this is to help for vertical alignment
$html .= '<span class="details">' . ' ' . '</span>';
$row[] = array(
'data' => $html,
'class' => 'list container-inline',
);
// COLUMN - Weight (hidden)
$row[] = drupal_render($form[$key]['weight']);
$rows[] = array(
'data' => $row,
'class' => 'draggable mime-' . $extension,
);
}
$output = '';
if (count($rows)) {
$output .= theme('table', array(), $rows, array(
'id' => 'upload-attachments',
));
}
$output .= drupal_render($form);
return $output;
}