7

I am trying to override view.xsd using Plugin and it's working on magento 2.1.x and 2.2.x but not working in 2.3.1.

I Add Same code To describe Here.

Extending the complexType named "imageType" with a custom image type

5
  • Can you post what you've tried, and also try the new code I've updated getSchema @Pratik Jun 3 '19 at 7:20
  • @PrathapGunasekaran Just try to override SchemaLocator Using preference and plugin in both case it's not working in 2.3.1
    – Pratik
    Jun 3 '19 at 9:51
  • Is that the overridden class works? Add a log to it and verify before going further Jun 3 '19 at 9:56
  • @PrathapGunasekaran I have much experience in magento so I try everything before post here including log.
    – Pratik
    Jun 3 '19 at 9:59
  • you must be finding it where it fails and where it went wrong. Is there any error while compilation or what that does give after been applied rewrite or interceptors Jun 3 '19 at 10:07
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\Framework\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\Framework\Config\SchemaLocator implements \Magento\Framework\Config\SchemaLocatorInterface
{
   protected $schema = null;
   /**
 * @param \Magento\Framework\Module\Dir\Reader $moduleReader
 */
public function getSchema()
{
    $result = sprintf(realpath(__DIR__ . '/../etc/view.xsd'));
    return $result;
}

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

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

Finally, add the view.xsd in the below path

app/code/Vendor/ModuleName/etc/view.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

5
  • 1
    Hello @Prathap Have you check link i post in Question ? You Post same Answer which I Add in Link and it's not working in 2.3.1
    – Pratik
    May 30 '19 at 5:08
  • Hey @Pratik Just give it a try and I don't think any of those answer using preference and this is working fine in M2.3. I've tested. May 30 '19 at 5:15
  • Have You check in 2.3.0 or 2.3.1 ?
    – Pratik
    May 30 '19 at 5:18
  • Is it working or not?? not much diff from 2.3 to 2.3.1 in regards of di May 30 '19 at 5:21
  • 2
    it's not working in 2.3.1.
    – Pratik
    May 30 '19 at 5:24

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.