upload_form_alter
- Versions
- 4.7 – 5
upload_form_alter($form_id, &$form)- 6 – 7
upload_form_alter(&$form, $form_state, $form_id)
Code
modules/upload/upload.module, line 212
<?php
function upload_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['workflow']['upload'] = array(
'#type' => 'radios',
'#title' => t('Attachments'),
'#default_value' => variable_get('upload_' . $form['#node_type']->type, 1),
'#options' => array(t('Disabled'), t('Enabled')),
);
}
if (!empty($form['#node_edit_form'])) {
$node = $form['#node'];
if (variable_get("upload_$node->type", TRUE)) {
// Attachments fieldset
$form['attachments'] = array(
'#type' => 'fieldset',
'#access' => user_access('upload files'),
'#title' => t('File attachments'),
'#collapsible' => TRUE,
'#collapsed' => empty($node->files),
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(drupal_get_path('module', 'upload') . '/upload.js'),
),
'#description' => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
'#weight' => 30,
);
// Wrapper for fieldset contents (used by ajax.js).
$form['attachments']['wrapper'] = array();
// Make sure necessary directories for upload.module exist and are
// writable before displaying the attachment form.
$path = file_directory_path();
$temp = file_directory_path('temporary');
// Note: pass by reference
if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY) || !file_prepare_directory($temp, FILE_CREATE_DIRECTORY)) {
$form['attachments']['#description'] = t('File attachments are disabled. The file directories have not been properly configured.');
if (user_access('administer site configuration')) {
$form['attachments']['#description'] .= ' ' . t('Please visit the <a href="@admin-file-system">file system configuration page</a>.', array('@admin-file-system' => url('admin/config/media/file-system')));
}
else {
$form['attachments']['#description'] .= ' ' . t('Please contact the site administrator.');
}
}
else {
$form['attachments']['wrapper'] += _upload_form($node);
}
$form['#submit'][] = 'upload_node_form_submit';
}
}
}
?>Login or register to post comments 