The file field for uploading is defined in the render callback of ManagedFile
:
public static function processManagedFile(&$element, FormStateInterface $form_state, &$complete_form) {
...
// The file upload field itself.
$element['upload'] = [
'#name' => 'files[' . $parents_prefix . ']',
'#type' => 'file',
'#title' => t('Choose a file'),
'#title_display' => 'invisible',
'#size' => $element['#size'],
'#multiple' => $element['#multiple'],
'#theme_wrappers' => [],
'#weight' => -10,
'#error_no_message' => TRUE,
];
So one way to change the output of the field is to define a custom form element which extends File
. The element can be themed as wanted.
And in the process callback of the custom widget the type of the upload element can be overwritten to use the newly defined element:
public static function process($element, FormStateInterface $form_state, $form) {
$element = parent::process($element, $form_state, $form);
$element['upload']['#type'] = 'myCustomFileElement';
return $element;
}