Search code examples
htmlcssprestashopprestashop-1.6

When I use custom html for prestashop 1.6.1.5 it deletes it after saving


Please, help me understand the nature of the problem. I use Prestashop 1.6.1.5.

I use custom HTML tags for my prestashop pages and it works great for the blog (Smart Blog v2.0.2) module in it. However, when I use the same for pages at the main menu (settings -> pages), it deletes all my HTML additions :(

I've allready changed isCleanHtml method in classes/Validate.php (it allways returns "True" by now. However, this have not helped me :(

Ex.: I want to use

    <div style="display: inline-block;"> 
<div style="display: inline-block; vertical-align: top; float: left; margin-right: 15px;"> 
<div style="display: inline-block; text-align: center;"><a href="link11"><img title="Title" src="link12" alt="Text alt" width="100" height="100" /></a></div> 
<div style="display: inline-block; text-align: center;"><a href="link21"><img title="Title" src="link22" alt="Text alt" width="100" height="100" /></a>
</div> </div> 
<p>Text</p> 
</div>

What I have after saving the page:

<div>
<div>
<div><a href="link11"><img title="Title" src="link12" alt="Text alt" width="100" height="100" /></a></div>
<div><a href="link21"><img title="Title" src="link22" alt="Text alt" width="100" height="100" /></a></div>
</div>
<p>Text</p>
</div>

Thank you!


Solution

  • The isCleanHtml function returning true will only prevent the Validate from returning an error. Instead you should remove the the validate field from the content in the CMS object. Because ObjectModel in formatFields has:

    $purify = (isset($data['validate']) && Tools::strtolower($data['validate']) == 'iscleanhtml') ? true : false;
          // Format field value
          $fields[$field] = ObjectModel::formatValue($value, $data['type'], false, $purify, !empty($data['allow_null']));
    

    So the purify only depends on the field having set the validate. And formatValue has:

    ...
    case self::TYPE_HTML:
          if ($purify) {
              $value = Tools::purifyHTML($value);
          }
    ...
    

    So it will still purifyHTML, because your field still has the 'validate' => 'isCleanHtml'. The solution should be simple: remove this part in 'content' from the CMS object in classes folder.