From e2c72bba147a88aa59e5dc8740925709d668bacc Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Wed, 20 Nov 2024 16:23:59 +0000 Subject: [PATCH] allow sorm to use other variants of I18NString, fixes #4891 Closes #4891 Merge request studip/studip!3664 --- lib/models/DatafieldEntryModelI18N.class.php | 2 ++ lib/models/SimpleORMap.class.php | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/models/DatafieldEntryModelI18N.class.php b/lib/models/DatafieldEntryModelI18N.class.php index bea234df067..810b3f84c18 100644 --- a/lib/models/DatafieldEntryModelI18N.class.php +++ b/lib/models/DatafieldEntryModelI18N.class.php @@ -27,6 +27,8 @@ class DatafieldEntryModelI18N extends DatafieldEntryModel { + protected string $i18n_class = I18NStringDatafield::class; + protected static function configure($config = []) { $config['i18n_fields']['content'] = true; diff --git a/lib/models/SimpleORMap.class.php b/lib/models/SimpleORMap.class.php index 0ecb9712ac3..03a4f771057 100644 --- a/lib/models/SimpleORMap.class.php +++ b/lib/models/SimpleORMap.class.php @@ -84,6 +84,11 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate */ protected static $performs_batch_operation = false; + /** + * Defines which variant of the I18NString class should be used + */ + protected string $i18n_class = I18NString::class; + /** * name of db table * @return string @@ -2248,7 +2253,10 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate $field = strtolower($field); if ($this->content[$field] === null || $this->content_db[$field] === null) { return $this->content[$field] !== $this->content_db[$field]; - } else if ($this->content[$field] instanceof I18NString || $this->content_db[$field] instanceof I18NString) { + } else if ( + $this->content[$field] instanceof I18NString + || $this->content_db[$field] instanceof I18NString + ) { // Trigger loading of translations if ($this->content[$field] instanceof I18NString) { $this->content[$field]->toArray(); @@ -2528,7 +2536,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate $value->setMetadata($meta); $this->content[$field] = $value; } else { - $this->content[$field] = new I18NString($value, null, $meta); + $this->content[$field] = new $this->i18n_class($value, null, $meta); } return $this->content[$field]; } -- GitLab