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.

Sanjay Chaudhary
  • 725
  • 8
  • 23

1 Answers1

3

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

Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
Prathap Gunasekaran
  • 3,269
  • 1
  • 16
  • 37
  • 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 '19 at 06:53