I'm under the impression that we can inject data into classes using di.xml and the $data array dependency. I'm struggling with getting it working however. Am I not understanding the concept correctly? Or am I missing some configuration?
Below is my (simplified) code.
etc/frontend/di.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="DannyNimmo\Subcategories\Block\ListCategory">
<arguments>
<argument xsi:type="array" name="data">
<item xsi:type="string" name="test">test</item>
</argument>
</arguments>
</type>
</config>
Block/ListCategory.php:
<?php
namespace DannyNimmo\Subcategories\Block;
class ListCategory
extends \Magento\Framework\View\Element\Template
implements \Magento\Framework\DataObject\IdentityInterface
{
public function __construct (
\Magento\Framework\View\Element\Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
var_dump($data);
}
}
Edit: I should say that I am seeing an empty array array(0) { } as the output.