public static function GeolocationGpxFileWidget::submit in Geolocation Field 8.3
Form submission handler for upload/remove button of formElement().
This runs in addition to and after file_managed_file_submit().
Overrides FileWidget::submit
See also
File
- modules/
geolocation_gpx/ src/ Plugin/ Field/ FieldWidget/ GeolocationGpxFileWidget.php, line 26
Class
- GeolocationGpxFileWidget
- Plugin implementation of the 'geolocation_gpx_file' widget.
Namespace
Drupal\geolocation_gpx\Plugin\Field\FieldWidgetCode
public static function submit($form, FormStateInterface $form_state) {
parent::submit($form, $form_state);
// During the form rebuild, formElement() will create field item widget
// elements using re-indexed deltas, so clear out FormState::$input to
// avoid a mismatch between old and new deltas. The rebuilt elements will
// have #default_value set appropriately for the current state of the field,
// so nothing is lost in doing this.
$button = $form_state
->getTriggeringElement();
$parents = array_slice($button['#parents'], 0, -2);
NestedArray::setValue($form_state
->getUserInput(), $parents, NULL);
$submitted_values = NestedArray::getValue($form_state
->getValues(), array_slice($button['#parents'], 0, -2));
foreach ($submitted_values as $delta => $submitted_value) {
foreach ($submitted_value['fids'] as $fid) {
/** @var \Drupal\file\FileInterface $file */
$file = File::load($fid);
$file
->setPermanent();
$file
->save();
}
}
}