View Single Post
  #1  
Old 08-10-2019, 08:28 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 446
 

Default HTML formatted text for custom entities

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
Code:
echo $value
, 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:
  1. The function to format the HTML text should go into model definition (Model/Author.php) or maybe repository (Model/Repo/Author.php)
  2. 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.
Attached Thumbnails
Click image for larger version

Name:	Unformatted.png
Views:	188
Size:	31.8 KB
ID:	5353  Click image for larger version

Name:	Formatted.png
Views:	182
Size:	20.4 KB
ID:	5354  
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France

Last edited by Ed B. : 08-10-2019 at 08:47 AM. Reason: I had forgotten to link images
Reply With Quote