public static function FileEditableWidget::process in File Entity (fieldable files) 8.2
Form API callback: Processes a file_generic field element.
Expands the file_generic type to include the description and display fields.
This method is assigned as a #process callback in formElement() method.
Overrides FileWidget::process
File
- src/
Plugin/ Field/ FieldWidget/ FileEditableWidget.php, line 23
Class
- FileEditableWidget
- File widget with support for editing the referenced file inline.
Namespace
Drupal\file_entity\Plugin\Field\FieldWidgetCode
public static function process($element, FormStateInterface $form_state, $form) {
$element = parent::process($element, $form_state, $form);
if (!$element['#files']) {
return $element;
}
foreach ($element['#files'] as $fid => $file) {
/** @var \Drupal\file\FileInterface $file */
$element['edit_button'] = [
'#name' => "file_editable_{$fid}",
'#type' => 'submit',
'#value' => t('Edit'),
'#ajax' => [
'url' => Url::fromRoute('entity.file.inline_edit_form', [
'file' => $fid,
]),
],
'#access' => $file
->access('update'),
];
}
return $element;
}