Fix HTML rendering for vendor notes links
Add proper HTML filtering to render mailto links and formatting in vendor notes. - Create HtmlArraySerialized backend model to prevent HTML escaping - Add filterOutputHtml() method to safely render HTML content - Update template to use HTML filtering - Decode HTML entities before display
This commit is contained in:
@@ -6,23 +6,27 @@ use Magento\Sales\Model\Order;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Framework\Filter\Template as FilterTemplate;
|
||||
|
||||
class VendorNotes extends Template
|
||||
{
|
||||
protected $_order;
|
||||
protected $_scopeConfig;
|
||||
protected $json;
|
||||
protected $filterTemplate;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Backend\Block\Template\Context $context,
|
||||
\Magento\Sales\Model\Order $order,
|
||||
ScopeConfigInterface $scopeConfig,
|
||||
Json $json,
|
||||
FilterTemplate $filterTemplate,
|
||||
array $data = []
|
||||
) {
|
||||
$this->_order = $order;
|
||||
$this->_scopeConfig = $scopeConfig;
|
||||
$this->json = $json;
|
||||
$this->filterTemplate = $filterTemplate;
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
|
||||
32
etc/Model/Config/Backend/HtmlArraySerialized.php
Normal file
32
etc/Model/Config/Backend/HtmlArraySerialized.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Shopkeeper\VendorNotes\Model\Config\Backend;
|
||||
|
||||
use Magento\Config\Model\Config\Backend\Serialized\ArraySerialized;
|
||||
|
||||
class HtmlArraySerialized extends ArraySerialized
|
||||
{
|
||||
/**
|
||||
* Process data before saving
|
||||
* Prevent HTML from being escaped in note fields
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function beforeSave()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
|
||||
if (is_array($value)) {
|
||||
// Don't escape HTML in the note field
|
||||
foreach ($value as &$row) {
|
||||
if (isset($row['note'])) {
|
||||
// Decode any previously encoded HTML entities
|
||||
$row['note'] = html_entity_decode($row['note'], ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
unset($row);
|
||||
}
|
||||
|
||||
$this->setValue($value);
|
||||
return parent::beforeSave();
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@
|
||||
<field id="vendor_mapping" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
|
||||
<label>Vendor Notes</label>
|
||||
<frontend_model>Shopkeeper\VendorNotes\Block\Adminhtml\Form\Field\VendorMapping</frontend_model>
|
||||
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
|
||||
<backend_model>Shopkeeper\VendorNotes\Model\Config\Backend\HtmlArraySerialized</backend_model>
|
||||
<comment>Add vendor names and their corresponding notes. The vendor name must match exactly as it appears in the product attribute.</comment>
|
||||
</field>
|
||||
</group>
|
||||
|
||||
@@ -15,7 +15,7 @@ $notes = $block->getVendorNotes();
|
||||
<span class="title"><?php echo __('Vendor Note %1', $index + 1); ?></span>
|
||||
</div>
|
||||
<div class="vendor-note-content" style="padding: 10px 0; line-height: 1.6;">
|
||||
<?php echo $note; // Output as HTML for links and multi-lines ?>
|
||||
<?php echo $this->filterOutputHtml($note); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($index < count($notes) - 1): ?>
|
||||
|
||||
Reference in New Issue
Block a user