function filefield_paths_widget_settings_alter in File (Field) Paths 6.2
Implements hook_widget_settings_alter().
File
- ./
filefield_paths.module, line 49 - Contains core functions for the FileField Paths module.
Code
function filefield_paths_widget_settings_alter(&$settings, $op, $widget) {
if (_filefield_paths_module_supported($widget['module'])) {
$fields = module_invoke_all('filefield_paths_field_settings');
$options = module_invoke_all('filefield_paths_form_options', $widget);
$field_options = module_invoke_all('filefield_paths_field_options');
switch ($op) {
case 'form':
// FileField Paths FAPI defaults.
$fapi = array(
'#type' => 'textfield',
'#maxlength' => '512',
);
// Build Fields.
$count = 0;
foreach ($fields as $key => $field) {
$settings['path_settings'][$key] = array_merge($field['fapi'], $fapi, array(
'#default_value' => isset($widget[$key]) ? $widget[$key] : $field['fapi']['#default_value'],
'#attributes' => array(
'class' => "filefield_paths filefield_paths-{$key}",
),
'#weight' => isset($field['fapi']['#weight']) ? $field['fapi']['#weight'] + $count * 2 : $count * 2,
));
// Build Field options.
if (count($field_options) > 0) {
$settings['path_settings']["{$key}_options-wrapper"] = array(
'#type' => 'fieldset',
'#attributes' => array(
'class' => "filefield_paths filefield_paths_fieldset filefield_paths-{$key}",
),
'#weight' => $count * 2 + 1,
);
$settings['path_settings']["{$key}_options-wrapper"]["{$key}_options"] = array(
'#title' => t('!field options', array(
'!field' => $field['fapi']['#title'],
)),
'#type' => 'checkboxes',
'#options' => $field_options,
'#default_value' => $widget["{$key}_options"],
);
}
$count++;
}
// Attach additional options.
$settings['path_settings']['options'] = array_merge($options, array(
'#weight' => ($count + 1) * 2,
));
// Token tree.
// To prevent un-usable 'field' tokens (text, number, etc), FileField
// Paths defines a 'filefield_paths' token type for internal use, which
// in turn invokes hook_filefield_paths_tokens() to allow other modules
// to include there own tokens.
$settings['path_settings']['token_tree'] = array(
'#value' => theme('token_tree', array(
'filefield_paths',
'node',
'user',
'global',
)),
'#weight' => ($count + 1) * 2 + 1,
);
break;
case 'save':
$settings = array_merge($settings, array_diff(array_keys($fields), $settings), array_keys($options));
foreach (array_keys($fields) as $field) {
$settings[] = "{$field}_options";
}
break;
}
}
foreach (_filefield_paths_includes() as $include) {
if (function_exists($function = "_filefield_paths_include_{$include}_widget_settings_alter")) {
$function($settings, $op, $widget);
}
}
}