[Issue] Inject Magento\Framework\App\State into Magento\Framework\View\Page\Config via constructor
This issue is automatically created based on existing pull request: magento/magento2#41336: Inject Magento\Framework\App\State into Magento\Framework\View\Page\Config via constructor
Description (*)
\Magento\Framework\View\Page\Config obtained \Magento\Framework\App\State through the private, deprecated getAreaResolver() getter, which called ObjectManager::getInstance() (with a phpcs:ignore) to avoid changing the constructor signature.
This PR adds State as an optional constructor argument ?App\State $appState = null, with the ObjectManager fallback in the constructor – the same backward compatible pattern already used for $escaper in this constructor. The private getAreaResolver() is removed and getRobots() uses the stored dependency. State is assigned before the constructor calls setElementAttribute(), so the dependency is available to any code running from the constructor.
Backward compatibility:
- No public or protected methods are removed or changed incompatibly; the constructor gains an optional trailing parameter, as allowed by the backward compatibility policy. There are no subclasses of this class in core, and the only DI configuration for it (
Magento/Backend/etc/adminhtml/di.xml) passes a named argument. Stateis now resolved whenPage\Configis created instead of on the firstgetRobots()call.Stateis a shared object with no dependency onPage\Config, created early during application bootstrap.
Tests:
- The unit test passes the
Statemock through the constructor instead of setting the private property via reflection. - A new test covers the
ObjectManagerfallback used when$appStateis not passed.
Related Pull Requests
- magento/magento2#39296 changes the
@deprecateddocblock ofgetAreaResolver(), which this PR removes. Whichever is merged second needs a trivial conflict resolution in that docblock.
Manual testing scenarios (*)
- Open any storefront page and check that the
robotsmeta tag in<head>has the configured value (Content > Design > Configuration > Search Engine Robots). - Open any admin page and check that the
robotsmeta tag isNOINDEX,NOFOLLOW.
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)
- README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- All automated tests passed successfully (all builds are green)
Source: magento/magento2