I have a custom model "Author" whose entities aren't multi-lingual.
Code:
namespace XLite\Module\EdB\Librairie\Model;
use XLite\Core\Database;
/**
* @Entity
* @Table (name="authors")
*/
class Author extends \XLite\Model\AEntity
which has a text field
Code:
/**
* Author Profil
*
* @var string
*
* @Column (type="text")
*/
protected $description = '';
with a getter function
Code:
public function getDescription()
{
return $this->description;
}
Now, my problem is that as these entities are not multilingual and the class Author doesn't extend \XLite\Model\Base\Catalog, I seem to get into trouble to format the description.
I tried to put
Code:
public function getViewDescription()
{
$value = $this->getDescription();
$value = \XLite\Model\Base\Catalog::getPreprocessedValue($value);
return static $value;
?: $value;
}
in Model/Author.php, but with these lines, the cache regeneration fails.
So I tried to put
Code:
public function describeAuthor()
{
$author_id = $this->getAuthorId();
$author = \XLite\Core\Database::getRepo('XLite\Module\EdB\Librairie\Model\
Author')->find($author_id);
$value = $author->getDescription();
$value = \XLite\Model\Base\Catalog::getPreprocessedValue($value);
return $value;
}
in the viewer file (View/Page/Customer/Author.php)
but, this outputs unformatted html code as in the first attached image.
If I put
, it works fine as in the second image.
Even though this last approach works, I think there should be a better way to
achieve the same result. That is:
- The function to format the HTML text should go into model definition (Model/Author.php) or maybe repository (Model/Repo/Author.php)
- One should be using "return" instead of "echo" to have better controle over the output via the twig file.
So, would anyone know a better way to do it? By the way, trying to transform the model "Author" into a multi-lingual one simply breaks the store.