function afb_advanced_process in Advanced Form Block 7
Custom process function overriding the default image widget one.
1 string reference to 'afb_advanced_process'
- afb_field_widget_form_alter in ./
afb.module - Alters the image widget to induce custom process function.
File
- ./
afb.module, line 403 - Allows administrators to create blockd of node add/edit forms.
Code
function afb_advanced_process($element, &$form_state, $form) {
$fid = isset($element['#value']['fid']) ? $element['#value']['fid'] : 0;
$rand = rand();
// Set some default element properties.
$element['#progress_indicator'] = empty($element['#progress_indicator']) ? 'none' : $element['#progress_indicator'];
$element['#file'] = $fid ? file_load($fid) : FALSE;
$element['#tree'] = TRUE;
$ajax_settings = array(
'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
'wrapper' => $element['#id'] . '-ajax-wrapper-' . $rand,
'effect' => 'fade',
'progress' => array(
'type' => $element['#progress_indicator'],
'message' => $element['#progress_message'],
),
);
// Set up the buttons first since we need to check if they were clicked.
$element['upload_button'] = array(
'#name' => implode('_', $element['#parents']) . '_upload_button',
'#type' => 'submit',
'#value' => t('Upload'),
'#validate' => array(),
'#submit' => array(
'file_managed_file_submit',
),
'#limit_validation_errors' => array(
$element['#parents'],
),
'#ajax' => $ajax_settings,
'#weight' => -5,
'#id' => drupal_html_id('test-upload-123-' . rand()),
);
$ajax_settings['progress']['type'] ? $ajax_settings['progress']['type'] == 'bar' : 'throbber';
$ajax_settings['progress']['message'] = NULL;
$ajax_settings['effect'] = 'none';
$element['remove_button'] = array(
'#name' => implode('_', $element['#parents']) . '_remove_button',
'#type' => 'submit',
'#value' => t('Remove'),
'#validate' => array(),
'#submit' => array(
'file_managed_file_submit',
),
'#limit_validation_errors' => array(
$element['#parents'],
),
'#ajax' => $ajax_settings,
'#weight' => -5,
'#id' => drupal_html_id('test-remove-' . rand()),
);
$element['fid'] = array(
'#type' => 'hidden',
'#value' => $fid,
);
// Add progress bar support to the upload if possible.
if ($element['#progress_indicator'] == 'bar' && ($implementation = file_progress_implementation())) {
$upload_progress_key = mt_rand();
if ($implementation == 'uploadprogress') {
$element['UPLOAD_IDENTIFIER'] = array(
'#type' => 'hidden',
'#value' => $upload_progress_key,
'#attributes' => array(
'class' => array(
'file-progress',
),
),
);
}
elseif ($implementation == 'apc') {
$element['APC_UPLOAD_PROGRESS'] = array(
'#type' => 'hidden',
'#value' => $upload_progress_key,
'#attributes' => array(
'class' => array(
'file-progress',
),
),
);
}
// Add the upload progress callback.
$element['upload_button']['#ajax']['progress']['path'] = 'file/progress/' . $upload_progress_key;
}
// The file upload field itself.
$element['upload'] = array(
'#name' => 'files[' . implode('_', $element['#parents']) . ']',
'#type' => 'file',
'#title' => t('Choose a file'),
'#title_display' => 'invisible',
'#size' => 22,
'#theme_wrappers' => array(),
'#weight' => -10,
'#id' => drupal_html_id('test-upload-' . rand()),
);
if ($fid && $element['#file']) {
$element['filename'] = array(
'#type' => 'markup',
'#markup' => theme('file_link', array(
'file' => $element['#file'],
)) . ' ',
'#weight' => -10,
);
}
// Add the extension list to the page as JavaScript settings.
if (isset($element['#upload_validators']['file_validate_extensions'][0])) {
$extension_list = implode(',', array_filter(explode(' ', $element['#upload_validators']['file_validate_extensions'][0])));
$element['upload']['#attached']['js'] = array(
array(
'type' => 'setting',
'data' => array(
'file' => array(
'elements' => array(
'#' . $element['#id'] . '-upload' => $extension_list,
),
),
),
),
);
}
// Prefix and suffix used for Ajax replacement.
$element['#prefix'] = '<div id="' . $element['#id'] . '-ajax-wrapper-' . $rand . '">';
$element['#suffix'] = '</div>';
return $element;
}