1

I have this custom configuration in my system.xml:

<system>
    <section id="general">
        <group id="store_information">
            <field id="support_phone" translate="label" type="text" sortOrder="21" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Support Phone Number</label>
            </field>
        </group>
    </section>
</system>

And I want to use this in my e-mail templates. So naturally, I try something like:

{{config path="general/store_information/support_phone"}}

Now this doesn't render the variable. which makes sense. This was also a security issue in Magento 1 since it would allow you to peek into system configuration settings, like API keys and stuff. So I have to include these parameters. Now I've added to my di.xml the setting to the config exclude list and the source model used by the email module:

<type name="Magento\Config\Model\Config\Export\ExcludeList">
    <arguments>
        <argument name="configs" xsi:type="array">
            <item name="general/store_information/support_phone" xsi:type="string">1</item>
        </argument>
    </arguments>
</type>
<type name="Magento\Email\Model\Source\Variables">
    <plugin name="custom_plugin" type="Vendor\Module\Plugin\Magento\Email\Model\Source\Variables"/>
</type>

But still it doesn't work. So where is the setting so I can whitelist certain configuration settings to be used in e-mail templates?

1 Answer 1

2

I found the problem. In my source model I hooked into the toOptionArray()-method, but this had to be the getData()-method:

public function afterGetData(\Magento\Email\Model\Source\Variables $subject, $result)
{
    $result = array_merge($result, [
        [
            'value' => 'general/store_information/support_phone',
            'label' => __('Support Phone Number')
        ],
    ]);

    return $result;
}

Why? Because the filter used by the e-mail module uses the getData()-method to determine whether or not a config setting is allowed to be used. See \Magento\Email\Model\Template\Filter::isAvailableConfigVariable() for more details.

1
  • great solution, pulled me out of a pickle!
    – circlesix
    Commented Aug 22, 2018 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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