magento / community-features

Magento Features Development is an Initiative to Allows Community Memebers Join to Development of Magento Features
46 stars 18 forks source link

Create VirtualTypes for Contollers using di.xml #117

Open qsolutions-pl opened 5 years ago

qsolutions-pl commented 5 years ago

Description

Make Magneto 2 even more flexible then it is now :-) We can create virtual types for blocks, models & most of the classes used in the system. I think it would be great if we could use VirtualTypes for Controllers.

Expected behavior

Use a custom class for an action that does not exists in CORE modules simply by adding 1 node in di.xml file

Benefits

We can extend core routers with VirtualTypes. For example: I need to add new action to a CORE controller / route, I can simply do it like this <virtualType name="Magento\CatalogSearch\Controller\Result\Somerandomaction" type="Qextensions\NoResults\Controller\Mycustomaction" />

Additional information

I hope my description is selfexplanatory

magento-engcom-team commented 5 years ago

Hi @qsolutions-pl. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop). For more details, please, review the Magento Contributor Assistant documentation.

@qsolutions-pl do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

magento-engcom-team commented 5 years ago

Hi @engcom-backlog-nazar. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

pmclain commented 5 years ago

A little background on why this doesn't work at the moment. The core routers build the action list using \Magento\Framework\Module\Dir\Reader::getActionFiles source, which loads the available actions by reading files contained in each module's Controller directory. https://github.com/magento/magento2/blob/5916c5a0c3eb595ace91448c35a170924cd1c4e1/lib/internal/Magento/Framework/Module/Dir/Reader.php#L123-L136

qsolutions-pl commented 5 years ago

@pmclain right, but I think extending virtual types would be awesome to create extra action to core controllers.

orlangur commented 5 years ago

@qsolutions-pl,

create extra action to core controllers

How is that different from URL rewrites?

How is line line in di.xml easier than an empty controller class in your module? With such change one would have to check not just Controller folder but also DI configuration to find a corresponding declaration.

sdzhepa commented 5 years ago

Hello @qsolutions-pl

According to the label "Feature Request" this ticket has been moved into "community-features" track

Thank you for collaboration

rhoerr commented 4 years ago

Was pointed toward this. My two cents:

It's kind of a different concept. VirtualTypes don't normally take effect by the sheer means of existing. You create a VirtualType and then inject it into some other class or list. That makes me hesitate.

I guess the same concept could be extended to work for controllers though. That would just be a bigger change from what exists now.

Which is to say, one could add some ActionsList class argument or something where you could explicitly define additional classes to treat as actions outside of the standard filesystems path. But then you'd have to address the problem of how Magento knows what frontname and controller path to use for each class given. I feel like convention would be a bad way to go there.