magento / magento/community-features

Eliminate the need for inheritance for action controllers

Open
#9 16 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

moved from magento2 Priority: P2
Dominant language
No language data
Stars
46
Forks
14
PR merge metrics
No merged PRs in 30d

Description

By design, all Magento action controllers should implement `\Magento\Framework\App\ActionInterface`. But some crucial request processing behavior (event dispatching, authorisation, etc) resides in classes like `\Magento\Framework\App\Action\Action` and `\Magento\Backend\App\AbstractAction`. So if an action controller implements the `ActionInterface` but does not inherit from one of these "layer supertype" classes, it will lose that crucial behavior.

So, Magento module developers do not have a way to create an action controller without using inheritance. To avoid inheritance ([see why](http://antonkril.github.io/code-reuse)), the request processing behavior should be extracted from "layer supertypes". Proposed solution is to move the behavior to action controller plugins.

Action controller should contain only its custom behavior.

AC:
- module developer does not have to extend from any class to create a fully functional action controller, implementing `\Magento\Framework\App\ActionInterface` is enough
- controllers "supertypes" (`\Magento\Backend\App\AbstractAction`, `\Magento\Framework\App\Action\Action`, `\Magento\Framework\App\Action\AbstractAction`) are deprecated
- magento supports both controller implementations (inheritance based and non-inheritance based)
- [optional] controllers are migrated

**Original Report**: https://github.com/magento/magento2/issues/9582 by @antonkril

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing Magento\Framework\App\Action\Action, Magento\Framework\App\Action\AbstractAction, and Magento\Backend\App\AbstractAction with the existing action-controller processing flow. Investigate how event dispatching and authorization can be provided through action-controller plugins. Done means an ActionInterface-only controller is fully functional, the supertypes are deprecated, and both inheritance-based and non-inheritance-based controllers remain supported.

Written by the indexing model from the issue text.

Assessment

Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.