#41345·magento2

[Issue] Inject Magento\Framework\App\State into Magento\Framework\View\Page\Config via constructor

Author: m2-assistant[bot]Created Sep 28, 2026Updated Sep 28, 2026
LabelsIssue: ready for confirmationReported on 2.4.x

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.
  • State is now resolved when Page\Config is created instead of on the first getRobots() call. State is a shared object with no dependency on Page\Config, created early during application bootstrap.

Tests:

  • The unit test passes the State mock through the constructor instead of setting the private property via reflection.
  • A new test covers the ObjectManager fallback used when $appState is not passed.

Related Pull Requests

  • magento/magento2#39296 changes the @deprecated docblock of getAreaResolver(), which this PR removes. Whichever is merged second needs a trivial conflict resolution in that docblock.

Manual testing scenarios (*)

  1. Open any storefront page and check that the robots meta tag in <head> has the configured value (Content > Design > Configuration > Search Engine Robots).
  2. Open any admin page and check that the robots meta tag is NOINDEX,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)