So, the new dependency injection approach requires me to inject everything I need into the contructor of an object. I get that.
But how is this more flexible?
I have my own Topmenu class in my own module. It extends \Magento\Theme\Block\Html\Topmenu.
In my custom code I am missing the DataObjectFactory. So I created my own constructor. There are two issues that really bug me:
- I have to copy the entire parent constructor into my own just to inject one additional object.
This is for real? It is not that I am stupid and did not get the point? I really have to do it this way? To me this is just tedious and extremely redundant. But if I don't do it, PHP just stops with an error. How is this an advantage?
- Now that I have copied the constructor...
public function __construct(
array $data = 
$this->nodeFactory = $nodeFactory;
$this->treeFactory = $treeFactory;
... I notice that $this->nodeFactory and $this->treeFactory are declared private. How am I supposed to extend a class/block this way?
And all this fuzz so I can have a simple dataobject that I can pass to an event I need to dispatch from my custom Topmenu.
Am I missing something here?