0

I'm trying to make use of a virtual type. I'm following the docs on this and everything should be pretty straight forward yet I'm kinda stuck.

This is what I have.

The class.

namespace Company\Extension\Model\Product\Attribute\Source;

class Test
{
    protected $string;

    public function __construct(String $test)
    {
        $this->string = $test;
    }

    public function test()
    {
        return $this->string;
    }
}

The di.xml

<config>
    <virtualType name="TestVirtualType" type="Company\Extension\Model\Product\Attribute\Source\Test">
        <arguments>
            <argument name="value" xsi:type="string">foo</argument>
        </arguments>
    </virtualType>
</config>

Now when running a simple php/bin magento

[Magento\Framework\Exception\LocalizedException]                                                            
  Invalid Document                                                                                            
  Element 'argument': The type definition is abstract.                                                        
  Line: 13                                                                                                    
  Internal error: xmlSchemaXPathProcessHistory, The state object to be removed is not the first in the list.  
  Line: 12                                                                                                    
  Internal error: xmlSchemaValidateChildElem, calling xmlRegExecPushString2().                                
  Line: 3                                                                                                     
  Internal error: xmlSchemaValidateElem, calling xmlSchemaStreamValidateChildElement().                       
  Line: 3                                                                                                     
  Internal error: xmlSchemaDocWalk, calling xmlSchemaValidateElem().                                          
  Line: 3     

I'm following the docs on this as well as many provided examples. I'm not really sure what I'm doing wrong. Any help or pointers in the right direction are highly appreciated

0

Found it. I forgot this part

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

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.