public static function Remote::process in FileField Sources 8
Process callback for file field source plugin.
Parameters
array $element: An associative array containing the properties and children of the generic input element.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
Return value
array The processed element.
Overrides FilefieldSourceInterface::process
File
- src/
Plugin/ FilefieldSource/ Remote.php, line 286
Class
- Remote
- A FileField source plugin to allow downloading a file from a remote server.
Namespace
Drupal\filefield_sources\Plugin\FilefieldSourceCode
public static function process(array &$element, FormStateInterface $form_state, array &$complete_form) {
$element['filefield_remote'] = [
'#weight' => 100.5,
'#theme' => 'filefield_sources_element',
'#source_id' => 'remote',
// Required for proper theming.
'#filefield_source' => TRUE,
'#filefield_sources_hint_text' => FILEFIELD_SOURCE_REMOTE_HINT_TEXT,
];
$element['filefield_remote']['url'] = [
'#type' => 'textfield',
'#description' => filefield_sources_element_validation_help($element['#upload_validators']),
'#maxlength' => NULL,
];
$class = '\\Drupal\\file\\Element\\ManagedFile';
$ajax_settings = [
'callback' => [
$class,
'uploadAjaxCallback',
],
'options' => [
'query' => [
'element_parents' => implode('/', $element['#array_parents']),
],
],
'wrapper' => $element['upload_button']['#ajax']['wrapper'],
'effect' => 'fade',
'progress' => [
'type' => 'bar',
'path' => 'file/remote/progress/' . $element['#entity_type'] . '/' . $element['#bundle'] . '/' . $element['#field_name'] . '/' . $element['#delta'],
'message' => t('Starting transfer...'),
],
];
$element['filefield_remote']['transfer'] = [
'#name' => implode('_', $element['#parents']) . '_transfer',
'#type' => 'submit',
'#value' => t('Transfer'),
'#validate' => [],
'#submit' => [
'filefield_sources_field_submit',
],
'#limit_validation_errors' => [
$element['#parents'],
],
'#ajax' => $ajax_settings,
];
return $element;
}