X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   HTML formatted text for custom entities (https://forum.x-cart.com/showthread.php?t=77093)

Ed B. 08-10-2019 08:28 AM

HTML formatted text for custom entities
 
2 Attachment(s)
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.

magehd 09-08-2019 07:38 AM

Re: HTML formatted text for custom entities
 
Are you using a View Class?


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

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.