From bfb941e2a09f451511fb64cb6a0cdf9362204188 Mon Sep 17 00:00:00 2001 From: Dominic Tubach Date: Fri, 4 Oct 2024 15:59:08 +0200 Subject: [PATCH] FileArrayFactory: Allow default value to be array The default value is an array, if it was fetched from the temporary values. --- .../src/Form/Control/FileArrayFactory.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/civiremote_entity/src/Form/Control/FileArrayFactory.php b/modules/civiremote_entity/src/Form/Control/FileArrayFactory.php index 224c33d..c2c3f30 100644 --- a/modules/civiremote_entity/src/Form/Control/FileArrayFactory.php +++ b/modules/civiremote_entity/src/Form/Control/FileArrayFactory.php @@ -61,6 +61,13 @@ public function createFormArray( ] + BasicFormPropertiesFactory::createFieldProperties($definition, $formState), ]; + // If the default value was fetched from the temporary values, it should + // be an array. If it was fetched from the field definition, it should be + // an \stdClass. + if (is_array($form['file']['#default_value'] ?? NULL)) { + $form['file']['#default_value'] = (object) $form['file']['#default_value']; + } + if (($form['file']['#default_value'] ?? NULL) instanceof \stdClass && is_string($form['file']['#default_value']->url ?? NULL) && is_string($form['file']['#default_value']->filename ?? NULL)