From 385918239cce3c6920d77ad2caf2e82844399d51 Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Wed, 17 Jul 2024 15:56:08 +0200 Subject: [PATCH] Pass encoded property values when updating model --- .../Contao2BackendView/ContaoWidgetManager.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Contao/View/Contao2BackendView/ContaoWidgetManager.php b/src/Contao/View/Contao2BackendView/ContaoWidgetManager.php index 78d1db73..ff33085c 100644 --- a/src/Contao/View/Contao2BackendView/ContaoWidgetManager.php +++ b/src/Contao/View/Contao2BackendView/ContaoWidgetManager.php @@ -115,13 +115,13 @@ public function __construct(EnvironmentInterface $environment, ModelInterface $m /** * Encode a value from the widget to native data of the data provider via event. * - * @param string $property The property. - * @param mixed $value The value of the property. - * @param PropertyValueBag $propertyValues The property value bag the property value originates from. + * @param string $property The property. + * @param mixed $value The value of the property. + * @param PropertyValueBagInterface $propertyValues The property value bag the property value originates from. * * @return mixed */ - public function encodeValue($property, $value, PropertyValueBag $propertyValues) + public function encodeValue($property, $value, PropertyValueBagInterface $propertyValues) { $environment = $this->getEnvironment(); $dispatcher = $environment->getEventDispatcher(); @@ -303,7 +303,14 @@ public function getWidget($property, PropertyValueBagInterface $inputValues = nu $controller = $environment->getController(); assert($controller instanceof ControllerInterface); - $values = new PropertyValueBag($inputValues->getArrayCopy()); + $values = new PropertyValueBag(); + foreach ($inputValues->getIterator() as $propertyName => $propertyValue) { + $values->setPropertyValue( + $propertyName, + $this->encodeValue($propertyName, $propertyValue, $inputValues) + ); + } + $controller->updateModelFromPropertyBag($model, $values); }