Skip to content

Commit

Permalink
Merge tag '2.3.16'
Browse files Browse the repository at this point in the history
Bugfix release 2.3.16

Fixes more encoding and decoding problems when updating
model values
  • Loading branch information
discordier committed Jul 19, 2024
2 parents efe5e2d + a06accd commit 188cc5c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/Contao/View/Contao2BackendView/ContaoWidgetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ protected function getUniqueId($propertyName)
* Retrieve the instance of a widget for the given property.
*
* @param string $property Name of the property for which the widget shall be retrieved.
* @param PropertyValueBagInterface $inputValues The input values to use (optional).
* @param PropertyValueBagInterface $inputValues The input values to use (optional) (RAW widget value format).
*
* @return Widget|null
*
Expand Down Expand Up @@ -398,7 +398,7 @@ protected function generateHelpText($property, Widget $widget)
* @param string $property The name of the property for which the widget shall be rendered.
* @param bool $ignoreErrors Flag if the error property of the widget shall get
* cleared prior rendering.
* @param PropertyValueBagInterface $inputValues The input values to use (optional).
* @param PropertyValueBagInterface $inputValues The input values to use (optional) (RAW widget value format).
*
* @return string
*
Expand Down Expand Up @@ -468,7 +468,9 @@ public function buildHiddenFields($value, string $propertyName): array
}

/**
* {@inheritDoc}
* Process RAW input values.
*
* @param PropertyValueBag $propertyValues The RAW property values from the input provider.
*
* @SuppressWarnings(PHPMD.Superglobals)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
Expand All @@ -487,6 +489,7 @@ public function processInput(PropertyValueBag $propertyValues): void
}

// Now get and validate the widgets.
$encodedValues = new PropertyValueBag();
foreach (\array_keys($propertyValues->getArrayCopy()) as $property) {
// NOTE: the passed input values are RAW DATA from the input provider - aka widget known values and not
// native data as in the model.
Expand All @@ -502,7 +505,7 @@ public function processInput(PropertyValueBag $propertyValues): void
}
} elseif ($widget->submitInput()) {
try {
$propertyValues->setPropertyValue(
$encodedValues->setPropertyValue(
$property,
$this->encodeValue($property, $widget->value, $propertyValues)
);
Expand All @@ -514,6 +517,9 @@ public function processInput(PropertyValueBag $propertyValues): void
}
}
}
foreach ($encodedValues->getArrayCopy() as $propertyName => $propertyValue) {
$propertyValues->setPropertyValue($propertyName, $propertyValue);
}

$_POST = $post;
Input::resetCache();
Expand Down
26 changes: 24 additions & 2 deletions src/Contao/View/Contao2BackendView/EditMask.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
class EditMask
{
Expand Down Expand Up @@ -522,7 +524,7 @@ protected function getEditButtons()
*
* @param ContaoWidgetManager $widgetManager The widget manager in use.
* @param PaletteInterface $palette The palette to use.
* @param PropertyValueBag|null $propertyValues The property values.
* @param PropertyValueBag|null $propertyValues The property values (model values).
*
* @return array
*
Expand All @@ -547,6 +549,26 @@ protected function buildFieldSet($widgetManager, $palette, $propertyValues)
$editInformation = System::getContainer()->get('cca.dc-general.edit-information');
assert($editInformation instanceof EditInformationInterface);

$rawValues = new PropertyValueBag();
if (null !== $propertyValues) {
foreach ($palette->getLegends() as $legend) {
$properties = $legend->getProperties($this->model, $propertyValues);
if (!$properties) {
continue;
}
foreach ($properties as $property) {
$propName = $property->getName();
$this->ensurePropertyExists($propName, $propertyDefinitions);
if ($propertyValues->hasPropertyValue($propName)) {
$rawValues->setPropertyValue(
$propName,
$widgetManager->decodeValue($propName, $propertyValues->getPropertyValue($propName))
);
}
}
}
}

$fieldSets = [];
$first = true;
foreach ($palette->getLegends() as $legend) {
Expand Down Expand Up @@ -593,7 +615,7 @@ protected function buildFieldSet($widgetManager, $palette, $propertyValues)
);
}

$fields[] = $widgetManager->renderWidget($property->getName(), $isAutoSubmit, $propertyValues);
$fields[] = $widgetManager->renderWidget($property->getName(), $isAutoSubmit, $rawValues);
}

$fieldSet['label'] = $legendName;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ControllerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function assembleAllChildrenFrom($model, $providerName = '');
* Update the current model from a post request. Additionally, trigger meta palettes, if installed.
*
* @param ModelInterface $model The model to update.
* @param PropertyValueBagInterface $propertyValues The value bag to retrieve the values from.
* @param PropertyValueBagInterface $propertyValues The value bag to retrieve the values from (model values).
*
* @return ControllerInterface
*/
Expand Down

0 comments on commit 188cc5c

Please sign in to comment.