function filefield_paths_form_submit in File (Field) Paths 6
Same name and namespace in other branches
- 8 filefield_paths.module \filefield_paths_form_submit()
- 5 filefield_paths.module \filefield_paths_form_submit()
- 7 filefield_paths.module \filefield_paths_form_submit()
Implements hook_form_submit().
1 string reference to 'filefield_paths_form_submit'
- filefield_paths_form_alter in ./
filefield_paths.module - Implements hook_form_alter().
File
- ./
filefield_paths.module, line 202 - Contains core functions for the FileField Paths module.
Code
function filefield_paths_form_submit($form, &$form_state) {
$ffp = array();
// Invoke hook_filefield_paths_form_submit().
foreach (module_implements('filefield_paths_form_submit') as $module) {
$function = "{$module}_filefield_paths_form_submit";
$function($form_state, $ffp);
}
if (count($ffp) > 0) {
$retroactive_update = FALSE;
$fields = module_invoke_all('filefield_paths_field_settings');
foreach ($ffp as $field_name => $field_data) {
$cols = $vals = $data = array();
foreach ($fields as $name => &$field) {
$field['settings'] = array(
'value' => $form_state['values']["ffp_{$field_name}"][$name],
'tolower' => $form_state['values']["ffp_{$field_name}"]["{$name}_cleanup"]["{$name}_tolower"],
'pathauto' => $form_state['values']["ffp_{$field_name}"]["{$name}_cleanup"]["{$name}_pathauto"],
'transliterate' => $form_state['values']["ffp_{$field_name}"]["{$name}_cleanup"]["{$name}_transliterate"],
);
// Store additional settings from addon modules.
if (isset($field['data'])) {
foreach ($field['data'] as $key => $value) {
$field['settings'][$key] = $form_state['values']["ffp_{$field_name}"][$value];
}
}
$cols[] = $field['sql'];
$vals[] = "'%s'";
$data[] = serialize($field['settings']);
}
$result = db_fetch_object(db_query("SELECT * FROM {filefield_paths} WHERE type = '%s' AND field = '%s'", $field_data['type'], $field_name));
// Update existing entry.
if (!empty($result)) {
foreach ($cols as &$col) {
$col .= " = '%s'";
}
db_query("UPDATE {filefield_paths} SET " . implode(', ', $cols) . " WHERE type = '%s' AND field = '%s'", array_merge($data, array(
$field_data['type'],
$field_name,
)));
}
else {
db_query("INSERT INTO {filefield_paths} (type, field, " . implode(', ', $cols) . ") VALUES ('%s', '%s', " . implode(', ', $vals) . ")", array_merge(array(
$field_data['type'],
$field_name,
), $data));
}
if ($form_state['values']["ffp_{$field_name}"]['retroactive_update']) {
$retroactive_update = TRUE;
$module = isset($form['#field']) ? $form['#field']['module'] : $field_name;
filefield_paths_batch_update($module, $field_name, arg(3));
}
variable_set("ffp_{$field_data['type']}_{$field_name}", $form_state['values']["ffp_{$field_name}"]['active_updating']);
}
if ($retroactive_update) {
// Run batch.
batch_process($form_state['redirect']);
}
}
}