You are here

function filefield_source_clipboard_process in FileField Sources 7

A #process callback to extend the filefield_widget element type.

1 string reference to 'filefield_source_clipboard_process'
filefield_source_clipboard_info in sources/clipboard.inc
Implements hook_filefield_source_info().

File

sources/clipboard.inc, line 61
A FileField extension to allow transfer of files through the clipboard.

Code

function filefield_source_clipboard_process($element, &$form_state, $form) {

  // If settings are needed later:

  //$instance = field_widget_instance($element, $form_state);

  //$settings = $instance['widget']['settings']['filefield_sources']['source_clipboard'];
  $element['filefield_clipboard'] = array(
    '#weight' => 100.5,
    '#theme' => 'filefield_source_clipboard_element',
    '#filefield_source' => TRUE,
    // Required for proper theming.
    '#filefield_sources_hint_text' => t('Enter filename then paste.'),
    '#description' => filefield_sources_element_validation_help($element['#upload_validators']),
  );
  $element['filefield_clipboard']['filename'] = array(
    '#type' => 'hidden',
    '#attributes' => array(
      'class' => array(
        'filefield-source-clipboard-filename',
      ),
    ),
  );
  $element['filefield_clipboard']['contents'] = array(
    '#type' => 'hidden',
    '#attributes' => array(
      'class' => array(
        'filefield-source-clipboard-contents',
      ),
    ),
  );
  $element['filefield_clipboard']['upload'] = array(
    '#type' => 'submit',
    '#value' => t('Upload'),
    '#ajax' => array(
      'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
      'wrapper' => $element['upload_button']['#ajax']['wrapper'],
      'effect' => 'fade',
      'progress' => array(
        'type' => 'throbber',
        'message' => t('Transfering file...'),
      ),
    ),
    '#validate' => array(),
    '#submit' => array(
      'filefield_sources_field_submit',
    ),
    '#limit_validation_errors' => array(
      $element['#parents'],
    ),
    '#attributes' => array(
      'style' => 'display: none;',
    ),
  );
  return $element;
}