Description
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]
);
- Create simple CLI command.
- Create
\Magento\Framework\View\File\Collector\Base
with param['subDir' => 'ui_component']
.
$baseFileCollector = $objectManager->create(Base::class, ['subDir' => 'ui_component']);
- 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
Type
Projects
Status