cancel
Showing results for 
Search instead for 
Did you mean: 

Instantiating block by layout with xsi:object argument

0 Kudos

Instantiating block by layout with xsi:object argument

Feature request from zbych, posted on GitHub Apr 05, 2015

Getting following error: Instance of Magento\Framework\Data\CollectionDataSourceInterface is expected, got Some\Backend\Class\Of\Model\Defined\ByMe instead.

I am not sure if it is intended, if it is, and it is within the rules of core functionality, then please cancel this issue and sorry for bothering. I am just not sure if blocks can accept only objects that inherits the Collection interface.

8 Comments
apiuser
New Member
Status changed to: Investigating
 
apiuser
New Member

Comment from vpelipenko, posted on GitHub Apr 06, 2015

@zbych, what should we do to reproduce this issue?

apiuser
New Member

Comment from orlangur, posted on GitHub Apr 06, 2015

There is no need to inherit from some collection class I believe, but Some\Backend\Class\Of\Model\Defined\ByMe must implement Magento\Framework\Data\CollectionDataSourceInterface.

apiuser
New Member

Comment from tzyganu, posted on GitHub Apr 06, 2015

@orlangur What's the purpose of the CollectionDataSourceInterface interface? It does not contain any methods at the moment.

apiuser
New Member

Comment from zbych, posted on GitHub Apr 06, 2015

@vpelipenko I prepared a simple module for you that reproduces this issue: https://www.dropbox.com/s/gh9cuzp4jmcgmtn/verde_test.tar.gz?dl=0

See explanation in layout. I hope it will help.

Thanks!

apiuser
New Member

Comment from vkorotun, posted on GitHub Apr 06, 2015

There is an layout argument of object type (xsi:type="object") you can pass to blocks' constructors. It is configured in di.xml, like showed here:

<virtualType name="layoutObjectArgumentInterpreter" type="Magento\Framework\View\Layout\Argument\Interpreter\Object">
    <arguments>
        <argument name="expectedClass" xsi:type="string">Magento\Framework\Data\CollectionDataSourceInterface</argument>
    </arguments>
</virtualType>

Originally this type of argument was developed for Admin Widget Grids to allow passing Collections as an argument to Grid constructor and it had being restricted to "Magento\Framework\Data\Collection". After a while instead of that there was created an empty marking interface, so now you may pass some custom types of collections with more soft restriction - they all should implement this very CollectionDataSourceInterface.

I'd like to consider an ideas if we should remove any restriction for "object" argument type and allow passing any type of objects.

apiuser
New Member

Comment from zbych, posted on GitHub Apr 07, 2015

@vpelipenko FYI: Update of Verde/Test module. I made there a mistake, but issue still occurs. @vkorotun you are right. Sometimes there is a need to configure object from layout, to keep Block reusable. After searching for other occurrences of xsi:type="object" in Magento layouts I found only Backend blocks using Collections, so I assumed it as "rule". That's why I was just not sure if it is bug.

Thanks for considering for removing constraint for Collection in that place. I think that it should expand power of layout and blocks.

Thanks!

apiuser
New Member

Comment from vkorotun, posted on GitHub Aug 04, 2016

Internal ticket: MAGETWO-56369