Skip to content
Snippets Groups Projects
Commit 6f33c1ee authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

allow sorm to use other variants of I18NString, fixes #4891

Closes #4891

Merge request studip/studip!3664
parent 3919ab80
No related branches found
No related tags found
No related merge requests found
...@@ -84,6 +84,11 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate ...@@ -84,6 +84,11 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/ */
protected static $performs_batch_operation = false; 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 * name of db table
* @return string * @return string
...@@ -2232,7 +2237,10 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate ...@@ -2232,7 +2237,10 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
$field = strtolower($field); $field = strtolower($field);
if ($this->content[$field] === null || $this->content_db[$field] === null) { if ($this->content[$field] === null || $this->content_db[$field] === null) {
return $this->content[$field] !== $this->content_db[$field]; 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 // Trigger loading of translations
if ($this->content[$field] instanceof I18NString) { if ($this->content[$field] instanceof I18NString) {
$this->content[$field]->toArray(); $this->content[$field]->toArray();
...@@ -2512,7 +2520,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate ...@@ -2512,7 +2520,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
$value->setMetadata($meta); $value->setMetadata($meta);
$this->content[$field] = $value; $this->content[$field] = $value;
} else { } else {
$this->content[$field] = new I18NString($value, null, $meta); $this->content[$field] = new $this->i18n_class($value, null, $meta);
} }
return $this->content[$field]; return $this->content[$field];
} }
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
class DatafieldEntryModelI18N extends DatafieldEntryModel class DatafieldEntryModelI18N extends DatafieldEntryModel
{ {
protected string $i18n_class = I18NStringDatafield::class;
protected static function configure($config = []) protected static function configure($config = [])
{ {
$config['i18n_fields']['content'] = true; $config['i18n_fields']['content'] = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment