From 6e3180c0b438fa32d185f1e6f66e737a8b4d2138 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Wed, 11 Oct 2023 18:24:31 +1300 Subject: [PATCH] FIX Apply multiupload auto-detection for upload fields (#1108) UploadField checks hasone components based on the field name to see if it can be a multiUpload field or not. We need to trigger that before changing the name of the field. --- src/Forms/EditFormFactory.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Forms/EditFormFactory.php b/src/Forms/EditFormFactory.php index a3c46eee..c8579af7 100644 --- a/src/Forms/EditFormFactory.php +++ b/src/Forms/EditFormFactory.php @@ -2,6 +2,7 @@ namespace DNADesign\Elemental\Forms; +use SilverStripe\AssetAdmin\Forms\UploadField; use SilverStripe\Control\RequestHandler; use SilverStripe\Core\Config\Configurable; use SilverStripe\Forms\DefaultFormFactory; @@ -66,6 +67,10 @@ protected function namespaceFields(FieldList $fields, array $context) $elementID = $context['Record']->ID; foreach ($fields->dataFields() as $field) { + if ($field instanceof UploadField) { + // Apply audo-detection of multi-upload before changing the name. + $field->setIsMultiUpload($field->getIsMultiUpload()); + } $namespacedName = sprintf(self::FIELD_NAMESPACE_TEMPLATE ?? '', $elementID, $field->getName()); $field->setName($namespacedName); }