View source
<?php
function _imagefield_tokens_support_list() {
return array(
'image_fupload_imagefield',
'imagefield',
'imagefield_crop',
);
}
function imagefield_tokens_form_alter(&$form, $form_state, $form_id) {
if (isset($form['widget_module']) && in_array($form['widget_module']['#value'], _imagefield_tokens_support_list())) {
$ifp = array(
'alt' => array(
'title' => 'ALT text',
'form_path' => &$form['widget']['alt_settings'],
),
'title' => array(
'title' => 'Title text',
'form_path' => &$form['widget']['title_settings'],
),
);
foreach ($ifp as $name => &$field) {
unset($field['form_path'][$name]['#suffix']);
$field['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(),
);
}
}
}
function imagefield_tokens_filefield_paths_process_file($new, &$file, $settings, $node, $update) {
if (in_array($file['widget'], _imagefield_tokens_support_list())) {
$file['field']['data']['alt'] = isset($file['field']['data']['alt']) ? $file['field']['data']['alt'] : '';
$file['field']['data']['title'] = isset($file['field']['data']['title']) ? $file['field']['data']['title'] : '';
$orig = array(
'alt' => $file['field']['data']['alt'],
'title' => $file['field']['data']['title'],
);
if (!empty($orig['alt'])) {
$file['field']['data']['alt'] = filefield_paths_process_string($orig['alt'], 'node', $node);
$file['field']['data']['alt'] = filefield_paths_process_string($file['field']['data']['alt'], 'field', array(
0 => $file['field'],
));
}
if (!empty($orig['title'])) {
$file['field']['data']['title'] = filefield_paths_process_string($orig['title'], 'node', $node);
$file['field']['data']['title'] = filefield_paths_process_string($file['field']['data']['title'], 'field', array(
0 => $file['field'],
));
}
}
}