From 91e8711fdf83e6b94ef4caea109548dd160c8bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 4 Mar 2024 22:10:28 +0100 Subject: [PATCH] Fixed problems with dynamically adding structural entities, when the arrows had spaces around them Related to #538 --- .../Type/Helper/StructuralEntityChoiceLoader.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Form/Type/Helper/StructuralEntityChoiceLoader.php b/src/Form/Type/Helper/StructuralEntityChoiceLoader.php index e668dfce..a527a44f 100644 --- a/src/Form/Type/Helper/StructuralEntityChoiceLoader.php +++ b/src/Form/Type/Helper/StructuralEntityChoiceLoader.php @@ -156,5 +156,20 @@ class StructuralEntityChoiceLoader extends AbstractChoiceLoader return $this; } + protected function doLoadChoicesForValues(array $values, ?callable $value): array + { + // Normalize the data (remove whitespaces around the arrow sign) and leading/trailing whitespaces + // This is required so that the value that is generated for an new entity based on its name structure is + // the same as the value that is generated for the same entity after it is persisted. + // Otherwise, errors occurs that the element could not be found. + foreach ($values as &$data) { + $data = trim($data); + $data = preg_replace('/\s*->\s*/', '->', $data); + } + unset ($data); + + return $this->loadChoiceList($value)->getChoicesForValues($values); + } + }