Injected objects into blocks via layout XMLs MUST implement CollectionDataSourceInterface

magento.stackexchange https://magento.stackexchange.com/questions/149493

  •  04-10-2020
  •  | 
  •  

Question

\Magento\Framework\Data\CollectionDataSourceInterface, to be more precise.

So imagine having this in - say - cms_index_index.xml:

<block class="Some\Block" name="block" template="tpl.phtml">
    <arguments>
        <argument name="someObj" xsi:type="object">Some\Object</argument>
    </arguments>
</block>

Block arguments of type object are resolved via \Magento\Framework\View\Layout\Argument\Interpreter\DataObject, class which does a seemingly useless thing: it's checking if your passed object is of type \Magento\Framework\Data\CollectionDataSourceInterface, throwing an exception if it's not.

Does anyone have the slightest clue as to why this validation is needed? The interface is - for now, at least - empty (marker interface).

Related post: http://magento-quickies.alanstorm.com/post/148712996610/a-typical-magento-2-programming-experience/embed

Was it helpful?

Solution

Reply posted here: https://github.com/magento/magento2/issues/1166#issuecomment-90084974:

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.

It's been moved in forums. It's the same as deleting it. So.. yeah, I guess that's it then.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top