cancel
Showing results for 
Search instead for 
Did you mean: 

Confusing backend area code constant name

0 Kudos

Confusing backend area code constant name

Feature request from erikhansen, posted on GitHub Jul 13, 2015

I've been working with Magento 2 for the past couple of months. There have several times where I've tried to find what constant to use for the backend area and have been distracted by an inappropriate constant.

The lib/internal/Magento/Framework/App/Area.php file contains these constants:

class Area implements \Magento\Framework\App\AreaInterface
{
    const AREA_GLOBAL = 'global';

    const AREA_FRONTEND = 'frontend';    

    const AREA_ADMIN    = 'admin';

If a developer is casually browsing the code, they may think that \Magento\Framework\App\Area::AREA_ADMIN is the appropriate constant to use to refer to the backend/adminhtml area.

However this is another constant in a different class that is the appropriate constant to use when referring to the backend area: \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE (the value of this constant is adminhtml)

To avoid this confusion for developers, I would recommend moving the backend constant into the \Magento\Framework\App\Area class and then add clear comments describing how the AREA_ADMIN constant differs from the AREA_ADMINHTML (or AREA_BACKEND, depending on what you decide to call it) constant.

6 Comments
apiuser
New Member
Status changed to: Investigating
 
apiuser
New Member

Comment from Vinai, posted on GitHub Jul 13, 2015

I'm all for resolving such confusing naming and placement issues, so :+1: from me. However, I guess the problem here is that Magento_Backend is a module, and the Magento\Framework\App\AreaInterface is part of the framework. Maybe the constant in the framework can be renamed to make it more distinct?

apiuser
New Member

Comment from joshdifabio, posted on GitHub Jul 13, 2015

I wonder whether the framework should really be concerned with what specific areas the application provides?

apiuser
New Member

Comment from erikhansen, posted on GitHub Jul 13, 2015

@Vinai At the very least, the \Magento\Framework\App\Area::AREA_ADMIN constant should be renamed.

From a cursory review of the codebase, it appears that the \Magento\Framework\App\Area::AREA_ADMIN constant may be able to be removed (or moved). If you search the codebase for instances of AREA_ADMIN, you'll only see a few usages:

  • The \Magento\Setup\Controller\Index::indexAction method - I didn't dig into why this constant is being used, but it seems to be the only place that actually uses this constant. Maybe the constant should be moved to this class?
  • The \Magento\Store\Model\App\Emulation::_restoreInitialLocale method uses it as a default parameter value, however that default appears to never be used.
  • A unit test

I did a quick search for all usages of 'admin' and it appears that there may be some literal strings that should be replaced to use this constant, but I'm not sure.

apiuser
New Member

Comment from antonkril, posted on GitHub Jul 14, 2015

Framework should not know about admin area. Only Backend constant should be used. I created task for cleanup.

apiuser
New Member

Comment from vpelipenko, posted on GitHub Jul 17, 2015

Internal ticket: MAGETWO-40232