function node_field_file_settings in Node Field 7.2
Settings form for file field.
1 string reference to 'node_field_file_settings'
- node_field_file_node_field_info_alter in modules/
node_field_file/ node_field_file.module - Implements hook_node_field_info_alter().
File
- modules/
node_field_file/ includes/ node_field_file.field.inc, line 29 - Field related functions for node_field_file module.
Code
function node_field_file_settings($node_field) {
$form = array();
$path = drupal_get_path('module', 'node_field_file');
module_load_include('inc', 'node_field_file', 'includes/node_field_file.formatter');
$formatters = node_field_file_formatter_info();
$options = array();
foreach ($formatters as $name => $item) {
$options[$name] = $item['#title'];
}
// Display formatters.
$default = empty($node_field['settings']['formatter']) ? key($formatters) : $node_field['settings']['formatter'];
$form['formatter'] = array(
'#type' => 'select',
'#title' => t('Display'),
'#options' => $options,
'#default_value' => $default,
);
$form['link_target'] = array(
'#type' => 'select',
'#title' => t('Link target'),
'#options' => array(
'_blank' => t('Open in new window'),
'_self' => t('Open in the same window'),
),
'#default_value' => empty($node_field['settings']['link_target']) ? '_blank' : $node_field['settings']['link_target'],
'#states' => array(
'visible' => array(
'#edit-settings-formatter' => array(
'value' => 'node_field_file_link',
),
),
),
);
$styles = image_styles();
$options = array(
'original' => t('original'),
);
foreach ($styles as $key => $style) {
$options[$key] = $style['name'];
}
// File extensions.
$extensions = empty($node_field['settings']['file_extensions']) ? array(
'txt',
) : $node_field['settings']['file_extensions'];
$form['file_extensions'] = array(
'#type' => 'textfield',
'#title' => t('Allowed file extensions'),
'#element_validate' => array(
'_file_generic_settings_extensions',
),
'#default_value' => $extensions,
'#description' => t('Separate extensions with a space or comma and do not include the leading dot.'),
'#required' => TRUE,
);
// Image style.
$default = empty($node_field['settings']['image_style']) ? key($options) : $node_field['settings']['image_style'];
$form['image_style'] = array(
'#type' => 'select',
'#title' => t('Image styles'),
'#options' => $options,
'#default_value' => $default,
'#attached' => array(
'js' => array(
$path . '/themes/js/node_field_file.settings.js',
),
),
);
// Size.
$form['size'] = array(
'#type' => 'container',
'#tree' => TRUE,
);
$default = empty($node_field['settings']['size']['width']) ? NODE_FIELD_FILE_DEFAULT_WIDTH : $node_field['settings']['size']['width'];
$form['size']['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => $default,
);
$default = empty($node_field['settings']['size']['height']) ? NODE_FIELD_FILE_DEFAULT_HEIGHT : $node_field['settings']['size']['height'];
$form['size']['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => $default,
);
// File system.
$options = array();
$default = empty($node_field['settings']['file_system']) ? 'public' : $node_field['settings']['file_system'];
$wrappers = array_intersect_key(file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE), array_flip(array(
'public',
'private',
)));
foreach ($wrappers as $scheme => $stream_wrapper) {
$options[$scheme] = $stream_wrapper['name'];
}
$form['file_system'] = array(
'#type' => 'radios',
'#title' => t('Upload destination'),
'#options' => $options,
'#description' => t('Select where the final files should be stored.
Private file storage has significantly more overhead than public files,
but allows restricted access to files within this field.'),
'#default_value' => $default,
);
return $form;
}