Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

HTML formatted text for custom entities

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #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:	182
Size:	31.8 KB
ID:	5353  Click image for larger version

Name:	Formatted.png
Views:	177
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
  #2  
Old 09-08-2019, 07:38 AM
  magehd's Avatar 
magehd magehd is offline
 

Member
  
Join Date: Sep 2017
Posts: 13
 

Default Re: HTML formatted text for custom entities

Are you using a View Class?
__________________
MageHD LLC
X-cart Partner
https://magehd.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:42 AM.

   

 
X-Cart forums © 2001-2020