From b1947a561bfbb7cb80643110c12334794ef3bc82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Tue, 19 Nov 2013 10:04:51 +0100 Subject: [PATCH] Improved backward compatibility for Contao 3.1 file IDs --- src/MadeYourDay/Contao/CustomElements.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/MadeYourDay/Contao/CustomElements.php b/src/MadeYourDay/Contao/CustomElements.php index fa5a7bc..4381a53 100644 --- a/src/MadeYourDay/Contao/CustomElements.php +++ b/src/MadeYourDay/Contao/CustomElements.php @@ -91,11 +91,28 @@ public function loadCallback($value, $dc) $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['inputType'] === 'rsce_file_tree' && $value ) { - if (strlen($value) === 36) { - $value = \String::uuidToBin($value); + // Multiple files + if (substr($value, 0, 2) === 'a:') { + $value = serialize(array_map(function($value) { + if (strlen($value) === 36) { + $value = \String::uuidToBin($value); + } + else if (is_numeric($value) && $file = \FilesModel::findByPk($value)) { + // Convert 3.1 format into 3.2 format + $value = $file->uuid; + } + return $value; + }, deserialize($value))); } + // Single file else { - $value = serialize(array_map('String::uuidToBin', deserialize($value))); + if (strlen($value) === 36) { + $value = \String::uuidToBin($value); + } + else if (is_numeric($value) && $file = \FilesModel::findByPk($value)) { + // Convert 3.1 format into 3.2 format + $value = $file->uuid; + } } }