Skip to content

[Issue] AppState emulateAreaCode was not respected by file collector #29656

Closed
@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #28917: AppState emulateAreaCode was not respected by file collector


Preconditions (*)

Magento 2.4-develop

The "hack" to emulate an area code via AppState->emulateAreaCode() is not respected by the base file collector. The consequence is that *.xml file in the emulated area is not found by the file collector.

Steps to reproduce (*)

The problem occurs in an extension I have built that require to access the adminhtml area from the graphql area. There are likely other modules in the Magento 2 that suffers from the same problem. However I can not point one such module without spending a considerable amount of time searching for it.

The following snippet suffer from this bug,

$data = $this->app_state->emulateAreaCode(   
  \Magento\Framework\App\Area::AREA_ADMINHTML,   
  [$this, "getDataSourceData"],  
  [$field, $args]
);  
  1. Create simple CLI command.
  2. Create \Magento\Framework\View\File\Collector\Base with param ['subDir' => 'ui_component'].

$baseFileCollector = $objectManager->create(Base::class, ['subDir' => 'ui_component']);

  1. Emulates callback inside adminhtml area.

$adminAreaEmulate = $objectManager->create(EmulatedAdminhtmlAreaProcessor::class);
$adminAreaEmulate->process([$baseFileCollector, 'getFiles'], [$theme, '*']);

Actual Result:
As result, we have files only from base area.
view/base/ui_component/*

Expected Result:
As result, we have files from base and adminhtml areas.
view/base/ui_component/*
view/adminhtml/ui_component/*

Questions or comments

I thinks someone more knowledgable should look into this issue. I have troubleshooted and my conclusions are as follows.

The base file collector is accessing the area code of the Theme with a call to getData('area').
The Theme has an override called getArea(), this method is never called by the base file collector.
This causes problems for modules that use "emulated area codes" via the
\Magento\Framework\App\State->emulateAreaCode() method.
The emulated area code is then not respected by the file collector since it access the data directly and not via the intended getArea() method in the Theme.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Metadata

Metadata

Assignees

Labels

Component: ViewEvent: MageCONF CD 2020Fixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P3May be fixed according to the position in the backlog.Progress: doneReported on 2.4.0Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions