function filefield_paths_form_alter in File (Field) Paths 5
Same name and namespace in other branches
- 6 filefield_paths.module \filefield_paths_form_alter()
- 7 filefield_paths.module \filefield_paths_form_alter()
Implementation of hook_form_alter().
File
- ./
filefield_paths.module, line 71 - Adds extra functionality to FileFields Path settings.
Code
function filefield_paths_form_alter($form_id, &$form) {
$ffp = array();
// Invoke hook_filefield_paths_form_alter().
foreach (module_implements('filefield_paths_form_alter') as $module) {
$function = $module . '_filefield_paths_form_alter';
$function($form, $ffp);
}
// If supporting module enabled, show FileField Paths settings form.
if (count($ffp) > 0) {
$fields = module_invoke_all('filefield_paths_field_settings');
foreach ($ffp as $field_name => $field_data) {
$result = db_fetch_object(db_query("SELECT * FROM {filefield_paths} WHERE type = '%s' AND field = '%s'", $field_data['type'], $field_name));
if (!empty($result)) {
foreach ($fields as &$field) {
$field['settings'] = unserialize($result->{$field}['sql']);
}
unset($field);
}
$count = 0;
foreach ($fields as $name => $field) {
$count++;
if (isset($field['form']) && is_array($field['form'])) {
$keys = array_keys($field['form']);
for ($i = 1; $i < count($field['form']); $i++) {
$field['form'][$keys[$i]]['#weight'] = ($count - 1) * 3 + 2 + $i;
}
unset($keys);
$field_data['form_path'] = array_merge($field_data['form_path'], $field['form']);
}
$name = isset($field_data['form_path'][$name]) ? $name : 'image_path';
$field_data['form_path']['#tree'] = TRUE;
$field_data['form_path'][$name]['#weight'] = ($count - 1) * 3;
// Set defualt value for patterns.
if (isset($field['settings']['value'])) {
$field_data['form_path'][$name]['#default_value'] = $field['settings']['value'];
if (isset($field['data'])) {
foreach ($field['data'] as $key => $value) {
$field_data['form_path'][$value]['#default_value'] = $field['settings'][$key];
}
}
}
$field_data['form_path'][$name . '_cleanup'] = array(
'#type' => 'fieldset',
'#title' => t('!title cleanup settings', array(
'!title' => $field['title'],
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ($count - 1) * 3 + 1,
'#attributes' => array(
'class' => $name . ' cleanup',
),
);
// Cleanup field with Pathauto module.
$field_data['form_path'][$name . '_cleanup'][$name . '_pathauto'] = array(
'#type' => 'checkbox',
'#title' => t('Cleanup using Pathauto') . '.',
'#default_value' => isset($field['settings']['pathauto']) ? $field['settings']['pathauto'] : 0,
'#description' => t('Cleanup !title using !url', array(
'!title' => $field['title'],
'!url' => l(t('Pathauto settings'), 'admin/build/path/pathauto'),
)),
);
if (!module_exists('pathauto')) {
$field_data['form_path'][$name . '_cleanup'][$name . '_pathauto']['#disabled'] = TRUE;
$field_data['form_path'][$name . '_cleanup'][$name . '_pathauto']['#default_value'] = 0;
}
// Convert field to lower case.
$field_data['form_path'][$name . '_cleanup'][$name . '_tolower'] = array(
'#type' => 'checkbox',
'#title' => t('Convert to lower case') . '.',
'#default_value' => isset($field['settings']['tolower']) ? $field['settings']['tolower'] : 0,
'#description' => t('Convert !title to lower case', array(
'!title' => $field['title'],
)) . '.',
);
// Transliterate field with Transliteration module.
$field_data['form_path'][$name . '_cleanup'][$name . '_transliterate'] = array(
'#type' => 'checkbox',
'#title' => t('Transliterate') . '.',
'#default_value' => isset($field['settings']['transliterate']) ? $field['settings']['transliterate'] : 0,
'#description' => t('Transliterate !title', array(
'!title' => $field['title'],
)) . '.',
);
if (!module_exists('transliteration')) {
$field_data['form_path'][$name . '_cleanup'][$name . '_transliterate']['#disabled'] = TRUE;
$field_data['form_path'][$name . '_cleanup'][$name . '_transliterate']['#default_value'] = 0;
}
// Replacement patterns for field.
$field_data['form_path'][$name . '_tokens'] = array(
'#type' => 'fieldset',
'#title' => t('!title replacement patterns', array(
'!title' => $field['title'],
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => theme('filefield_paths_token_help'),
'#weight' => ($count - 1) * 3 + 2,
'#attributes' => array(
'class' => $name . ' tokens',
),
);
}
// Retroactive updates.
$field_data['form_path']['retroactive_update'] = array(
'#type' => 'checkbox',
'#title' => t('Retroactive update'),
'#description' => t('Move and rename previously uploaded files') . '.' . '<br /> <strong style="color: #FF0000;">' . t('Warning') . ':</strong> ' . t('This feature should only be used on developmental servers or with extreme caution') . '.',
'#weight' => 10,
);
$form['#submit']['filefield_paths_form_submit'] = array();
}
}
}