function itweak_upload_form_alter in iTweak Upload 6.2
Implementation of hook_form_alter().
File
- ./
itweak_upload.module, line 547 - iTweakUpload - Tweak attachments display and file upload forms.
Code
function itweak_upload_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
//? if (variable_get("upload_$node->type", TRUE)) {
$form['#pre_render'][] = '_itweak_upload_upload_form_prerender';
$form['#submit'][] = '_itweak_upload_files_imagecache_flush';
$form += array(
'#input' => TRUE,
'#itu' => 1,
);
// '#input'=1 hacks FAPI to call #process handler on the form
$form['#process'][] = '_itweak_upload_process';
// }
}
switch ($form_id) {
case 'upload_js':
$cached_form_state = array();
if (empty($_POST) || !($cached_form = form_get_cache($_POST['form_build_id'], $cached_form_state)) || !isset($cached_form['#node']) || !isset($cached_form['attachments'])) {
// ERROR! Let upload.module handle it
return;
}
$node_type = $cached_form['#node']->type;
if (_itweak_upload_get_setting('', 'upload_preview', $node_type, 1)) {
$group = $cached_form['#node']->nid ? $cached_form['#node']->nid : 'new';
$vid = $cached_form['#node']->vid;
_itweak_upload_files_thumbnails($form['files'], $vid, NULL, $node_type, $group);
}
$form['#pre_render'][] = '_itweak_upload_upload_form_prerender_themes';
$form['files']['#node_type'] = $node_type;
$form += array(
'#input' => TRUE,
);
// '#input'=1 hacks FAPI to call #process handler on the form
$form['#process'][] = '_itweak_upload_process';
break;
case 'comment_form':
if (module_exists('comment_upload')) {
$nid = $form['nid']['#value'];
// All we need is node type.
$node = node_load($nid);
// Expecting it to be cached data.
// [#917270] Fix $form['#node']->type for comment_driven
// $form['#node']->type = 'comment'; // set 'comment' type for _itweak_upload_upload_form_prerender()
// $form['#node']->parent_type = $node->type; // pass node_type into _itweak_upload_upload_form_prerender()
$form['#node']->itu_comment = TRUE;
// tell its 'comment' to _itweak_upload_upload_form_prerender()
if (!isset($form['#node']->type)) {
$form['#node']->type = $node->type;
// pass node_type into _itweak_upload_upload_form_prerender()
}
$form['#node']->vid = $node->vid;
$form['#pre_render'][] = '_itweak_upload_upload_form_prerender';
$form['#submit'][] = '_itweak_upload_files_imagecache_flush';
$form += array(
'#input' => TRUE,
'#itu' => 1,
);
// '#input'=1 hacks FAPI to call #process handler on the form
$form['#process'][] = '_itweak_upload_process';
if (isset($form['preview'])) {
// Fix for broken comment previews
// [#579900] [#302240] [#715178] ?[#429006] ?[#666680] ?[#397616]
// Short scoop: 6.14 changed FAPI 'button' (opposed to 'submit') - it stopped getting the form rebuild upon comment preview (pick it from cache instead).
// $form['preview']['#executes_submit_callback'] = TRUE;
$form['preview']['#type'] = 'submit';
}
}
break;
case 'comment_upload_js':
if (module_exists('comment_upload')) {
$cached_form_state = array();
if (empty($_POST) || !($cached_form = form_get_cache($_POST['form_build_id'], $cached_form_state)) || !isset($cached_form['#comment_upload_storage']) || !isset($cached_form['attachments'])) {
// ERROR! Let upload.module handle it
return;
}
$nid = $cached_form['nid']['#value'];
// All we need is node type.
$node = node_load($nid);
// Expecting it to be cached data.
$node_type = $node->type;
if (_itweak_upload_get_setting('', 'upload_preview', $node_type, 1)) {
$vid = $node->vid;
$cid = $cached_form['cid']['#value'] ? $cached_form['cid']['#value'] : 'new';
$group = 'c' . $cid;
_itweak_upload_files_thumbnails($form['files'], $vid, $cid, $node_type, $group);
}
$form['#pre_render'][] = '_itweak_upload_upload_form_prerender_themes';
$form['files']['#node_type'] = $node_type;
$form += array(
'#input' => TRUE,
);
// '#input'=1 hacks FAPI to call #process handler on the form
$form['#process'][] = '_itweak_upload_process';
}
break;
case 'node_type_form':
module_load_include('admin.inc', 'itweak_upload');
_itweak_upload_node_type_form($form);
break;
case 'upload_admin_settings':
module_load_include('admin.inc', 'itweak_upload');
_itweak_upload_admin_settings($form);
break;
}
}