2

I have added payment method in magento2.2. The payment method has an input box typed textarea. I want to add a href link but it's not supporting it. Is there a way to enable HTML tags. enter image description here

I am getting this in frontend

enter image description here

  • Please add code how you get value at front end? – Rohan Hapani Apr 24 at 9:30
  • It's a 3rd party module, I just want to enable html tags for instruction @RohanHapani – Bhakti Thakkar Apr 24 at 9:39
1

Although there was a similar question answered on Magento SE a few days ago, I would like to answer it.

As I understood you want to add some HTML tags to a custom payment method.

By default Magento escapeHtml when rendering the instructions for the payment methods.

We need to Create a small module which will override getInstructions function. For reference, I assume that the name of custom payment method module is Company_CustomModule

let's create a module Stack_Instructions.

app/code/Stack/Instructions/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Stack_Instructions',
__DIR__
);

app/code/Stack/Instructions/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Stack_Instructions" setup_version="1.0.0">
   </module>
</config>

app/code/Stack/Instructions/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Company\CustomModule\Model\InstructionsConfigProvider" type="Stack\Instructions\Model\Rewrite\InstructionsConfigProvider" />
</config>

app/code/Stack/Instructions/Model/Rewrite/InstructionsConfigProvider.php

<?php

namespace Stack\Instructions\Model\Rewrite;

class InstructionsConfigProvider extends \Company\CustomModule\Model\InstructionsConfigProvider

{
    public function getInstructions($code)
    {
        return nl2br($this->methods[$code]->getInstructions());// removed escapeHtml function!
    }

}
0

I assume the 3rd party payment module name is "Company_MyModule"

Please find the config provider class of your 3rd party payment module. In general, this class exists under Company/MyModule/Model/ and class names may be ConfigProvider

Once you identify the ConfigProvider class, you may try to update the class as follows.

Note: Basically, you need to update the ConfigProvider class to insert a dependency for \Magento\Cms\Model\Template\FilterProvider which will help to Parse the config field value.

I assume the ConfigProvider class name is ConfigProvider.php under folder app/code/Company/MyModule/Model/

Update the class as follows:

<?php

namespace Company\MyModule\Model;

.................

use Magento\Checkout\Model\ConfigProviderInterface;
.................


/**
 * Class ConfigProvider
 */
final class ConfigProvider implements ConfigProviderInterface
{

   ................    
   protected $templateProcessor;
   ................



    public function __construct(
    ................ ,
    ................ ,
    \Magento\Cms\Model\Template\FilterProvider $templateProcessor     
    )
    {
        ................
        $this->templateProcessor = $templateProcessor;
        ................

    }



    /**
     * Retrieve assoc array of checkout configuration
     *
     * @return array
     */
    public function getConfig()
    {        

        $configArray = [
            'payment' => [
                self::CODE => [
                    'active' => ......,
                    'title' => ....,
                    'instructions' => $this->filterOutputHtml('SYSTEM-CONFIG-VALUE-FOR-instructions'),

                ]
            ]
        ];
        return $configArray;
    }


    public function filterOutputHtml($string)
 {
    return $this->templateProcessor->getPageFilter()->filter($string);
  }  
}
  • Thank you and I just wanted to know where can I find this file ConfigProvider.php in vendor? – Bhakti Thakkar Apr 24 at 12:32
  • I want to update it for Magento payment method also – Bhakti Thakkar Apr 24 at 12:35
  • You can find it using your module name. can you confirm your 3rd party module is under the vendor directory? if yes look for the company name . Thank you – Pritam Info 24 Apr 24 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.