function filefield_source_imce_process in FileField Sources 6
Same name and namespace in other branches
- 7 sources/imce.inc \filefield_source_imce_process()
A #process callback to extend the filefield_widget element type.
1 string reference to 'filefield_source_imce_process'
- filefield_source_imce_info in sources/
imce.inc - Implements hook_filefield_source_info().
File
- sources/
imce.inc, line 96 - A FileField extension to allow referencing of files from IMCE.
Code
function filefield_source_imce_process($element, $edit, &$form_state, $form) {
$field = content_fields($element['#field_name'], $element['#type_name']);
$element['filefield_imce'] = array(
'#weight' => 100.5,
'#theme' => 'filefield_source_imce_element',
'#filefield_source' => TRUE,
// Required for proper theming.
'#description' => filefield_sources_element_validation_help($element['#upload_validators']),
);
$filepath_id = $element['#id'] . '-imce-path';
$display_id = $element['#id'] . '-imce-display';
$select_id = $element['#id'] . '-imce-select';
$element['filefield_imce']['file_path'] = array(
// IE doesn't support onchange events for hidden fields, so we use a
// textfield and hide it from display.
'#type' => 'textfield',
'#value' => '',
'#id' => $filepath_id,
'#attributes' => array(
'onblur' => "if (this.value.length > 0) { jQuery('#{$select_id}').triggerHandler('mousedown'); }",
'style' => 'position:absolute; left: -9999em',
),
);
$imce_function = 'window.open(\'' . url('filefield/imce/' . $element['#type_name'] . '/' . $element['#field_name'], array(
'query' => 'app=' . rawurlencode($field['widget']['label']) . '|url@' . $filepath_id,
)) . '\', \'\', \'width=760,height=560,resizable=1\'); return false;';
$element['filefield_imce']['display_path'] = array(
'#type' => 'markup',
'#value' => '<span id="' . $display_id . '" class="filefield-sources-imce-display">' . t('No file selected') . '</span> (<a class="filefield-sources-imce-browse" href="#" onclick="' . $imce_function . '">' . t('browse') . '</a>)',
);
$element['filefield_imce']['select'] = array(
'#name' => implode('_', $element['#array_parents']) . '_imce_select',
'#type' => 'submit',
'#value' => t('Select'),
'#validate' => array(),
'#submit' => array(
'node_form_submit_build_node',
),
'#name' => $element['#name'] . '[filefield_imce][button]',
'#id' => $select_id,
'#attributes' => array(
'style' => 'display: none;',
),
'#ahah' => array(
'path' => 'filefield/ahah/' . $element['#type_name'] . '/' . $element['#field_name'] . '/' . $element['#delta'],
'wrapper' => $element['#id'] . '-ahah-wrapper',
'method' => 'replace',
'effect' => 'fade',
),
);
return $element;
}