function filefield_source_imce_process in FileField Sources 7
Same name and namespace in other branches
- 6 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 100 - A FileField extension to allow referencing of files from IMCE.
Code
function filefield_source_imce_process($element, &$form_state, $form) {
$instance = field_widget_instance($element, $form_state);
$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' => '',
'#attributes' => array(
'id' => $filepath_id,
'onblur' => "if (this.value.length > 0) { jQuery('#{$select_id}').triggerHandler('mousedown'); }",
'style' => 'position:absolute; left: -9999em',
),
);
$imce_function = 'window.open(\'' . url('file/imce/' . $element['#entity_type'] . '/' . $element['#bundle'] . '/' . $element['#field_name'], array(
'query' => array(
'app' => $instance['label'] . '|url@' . $filepath_id,
),
)) . '\', \'\', \'width=760,height=560,resizable=1\'); return false;';
$element['filefield_imce']['display_path'] = array(
'#type' => 'markup',
'#markup' => '<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(
'filefield_sources_field_submit',
),
'#limit_validation_errors' => array(
$element['#parents'],
),
'#name' => $element['#name'] . '[filefield_imce][button]',
'#id' => $select_id,
'#attributes' => array(
'style' => 'display: none;',
),
'#ajax' => array(
'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
'wrapper' => $element['upload_button']['#ajax']['wrapper'],
'method' => 'replace',
'effect' => 'fade',
),
);
return $element;
}