You are here

function filefield_source_reference_process in FileField Sources 7

Same name and namespace in other branches
  1. 6 sources/reference.inc \filefield_source_reference_process()

A #process callback to extend the filefield_widget element type.

1 string reference to 'filefield_source_reference_process'
filefield_source_reference_info in sources/reference.inc
Implements hook_filefield_source_info().

File

sources/reference.inc, line 110
A FileField extension to allow referencing of existing files.

Code

function filefield_source_reference_process($element, &$form_state, $form) {
  $element['filefield_reference'] = array(
    '#weight' => 100.5,
    '#theme' => 'filefield_source_reference_element',
    '#filefield_source' => TRUE,
    // Required for proper theming.
    '#filefield_sources_hint_text' => FILEFIELD_SOURCE_REFERENCE_HINT_TEXT,
  );
  $element['filefield_reference']['autocomplete'] = array(
    '#type' => 'textfield',
    '#autocomplete_path' => 'file/reference/' . $element['#entity_type'] . '/' . $element['#bundle'] . '/' . $element['#field_name'],
    '#description' => filefield_sources_element_validation_help($element['#upload_validators']),
  );
  $element['filefield_reference']['select'] = array(
    '#name' => implode('_', $element['#array_parents']) . '_autocomplete_select',
    '#type' => 'submit',
    '#value' => t('Select'),
    '#validate' => array(),
    '#submit' => array(
      'filefield_sources_field_submit',
    ),
    '#name' => $element['#name'] . '[filefield_reference][button]',
    '#limit_validation_errors' => array(
      $element['#parents'],
    ),
    '#ajax' => array(
      'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
      'wrapper' => $element['upload_button']['#ajax']['wrapper'],
      'effect' => 'fade',
    ),
  );
  return $element;
}