2

I need to modify the email_templates.xsd file of Magento_Email module.

So can I modify it, if yes then how and if not then can I use custom file instead of original .xsd file.I tried using my custom .xsd file but it's not working.

Any help would be appreciated.

2

Try this, you can extend using preference

Add di.xml in the below folder

app/code/Vendor/ModuleName/etc/di.xml

then add the below code to it

<?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="Magento\Email\Model\Template\Config\SchemaLocator" type="Vendor\ModuleName\Config\SchemaLocator" />
</config>

then add SchemaLocator.php in the below path

app/code/Vendor/ModuleName/Config/SchemaLocator.php

then add the below code to it

<?php
namespace Vendor\ModuleName\Config;
use Magento\Framework\Module\Dir;

class SchemaLocator extends \Magento\Email\Model\Template\Config\SchemaLocator implements 
\Magento\Framework\Config\SchemaLocatorInterface
{
   protected $schema = null;
   /**
 * @param \Magento\Framework\Module\Dir\Reader $moduleReader
 */
public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader)
{
    $this->_schema = $moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Vendor_Module') . '/email_templates.xsd';
}

/**
 * {@inheritdoc}
 */
public function getSchema()
{
    return $this->_schema;
}

/**
 * {@inheritdoc}
 */
public function getPerFileSchema()
{
    return $this->_schema;
}
}

the above code will change the path of email_templates.xsd to your custom module from core.

Finally, add the email_templates.xsd in the below path

app/code/Vendor/ModuleName/etc/email_templates.xsd

then you can add you changes there.

NOTE : This is working example in M2.3 and in previous version used plugin instead of preference

  • 1
    Thanks for your answer, it saved a lot of time and I would just like to update your answer as it was throwing "unknown validation error" kind of issue. Rest is perfect. – Sanjay Chaudhary Mar 30 at 6:53

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.