From 6f33c1ee793d28ff46d80d6393dc47952241ae9c 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/classes/SimpleORMap.php | 12 ++++++++++-- lib/models/DatafieldEntryModelI18N.php | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/classes/SimpleORMap.php b/lib/classes/SimpleORMap.php index f3993c2706e..d8cdb8eca06 100644 --- a/lib/classes/SimpleORMap.php +++ b/lib/classes/SimpleORMap.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 @@ -2232,7 +2237,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(); @@ -2512,7 +2520,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]; } diff --git a/lib/models/DatafieldEntryModelI18N.php b/lib/models/DatafieldEntryModelI18N.php index aa93a638e66..19974111a09 100644 --- a/lib/models/DatafieldEntryModelI18N.php +++ b/lib/models/DatafieldEntryModelI18N.php @@ -28,6 +28,8 @@ class DatafieldEntryModelI18N extends DatafieldEntryModel { + protected string $i18n_class = I18NStringDatafield::class; + protected static function configure($config = []) { $config['i18n_fields']['content'] = true; -- GitLab