Allow l11n type to reference the l11n.

This commit is contained in:
Dennis Eichhorn 2023-05-30 01:34:01 +02:00
parent 0900e31d45
commit 06f1784418

View File

@ -40,6 +40,14 @@ class BaseStringL11nType implements \JsonSerializable
*/
public string $title = '';
/*
* String l11n
*
* @var string | BaseStringL11n
* @since 1.0.0
*/
public string | BaseStringL11n $l11n = '';
/**
* Is the l11n type required for an item?
*
@ -72,6 +80,44 @@ class BaseStringL11nType implements \JsonSerializable
return $this->id;
}
/**
* Set l11n
*
* @param string|BaseStringL11n $l11n Tag article l11n
* @param string $lang Language
*
* @return void
*
* @since 1.0.0
*/
public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void
{
if ($l11n instanceof BaseStringL11n) {
$this->l11n = $l11n;
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
} else {
$this->l11n = new BaseStringL11n();
$this->l11n->content = $l11n;
$this->l11n->setLanguage($lang);
}
}
/**
* @return string
*
* @since 1.0.0
*/
public function getL11n() : string
{
if (!isset($this->l11n)) {
return '';
}
return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n;
}
/**
* {@inheritdoc}
*/