Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation: #95235 - Public getter of services in ModuleTemplate #2672

Closed
sabbelasichon opened this issue Oct 6, 2021 · 0 comments · Fixed by #2788
Closed

Deprecation: #95235 - Public getter of services in ModuleTemplate #2672

sabbelasichon opened this issue Oct 6, 2021 · 0 comments · Fixed by #2788

Comments

@sabbelasichon
Copy link
Owner

Deprecation: #95235 - Public getter of services in ModuleTemplate

https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/11.5/Deprecation-95235-PublicGetterOfServicesInModuleTemplate.html
.. include:: ../../Includes.txt

=================================================================
Deprecation: #95235 - Public getter of services in ModuleTemplate

See :issue:95235

Description

The public methods :php:getIconFactory and :php:getPageRenderer
in :php:TYPO3\CMS\Backend\Template\ModuleTemplate have been marked as deprecated,
since using this getters only hides the dependencies to those services.

Impact

Calling either :php:getIconFactory or :php:getPageRenderer will
trigger a PHP :php:E_USER_DEPRECATED error. The extension scanner also detects
such calls as weak match.

Affected Installations

All installations calling the methods in custom extension code.

Migration

Inject the corresponding services :php:TYPO3\CMS\Core\Imaging\IconFactory
and :php:TYPO3\CMS\Core\Page\PageRenderer directly in your class.

A current Extbase backend controller might look like:

.. code-block:: php

class MyController extends ActionController
{
    protected ModuleTemplateFactory $moduleTemplateFactory;

    public function __construct(ModuleTemplateFactory $moduleTemplateFactory)
    {
        $this->moduleTemplateFactory = $moduleTemplateFactory;
    }

    public function myAction(): ResponseInterface
    {
        $moduleTemplate = $this->moduleTemplateFactory->create($this->request);
        $moduleTemplate->getPageRenderer()->loadRequireJsModule('Vendor/Extension/MyJsModule');
        $moduleTemplate->setContent($moduleTemplate->getIconFactory()->getIcon('some-icon', Icon::SIZE_SMALL)->render());
        return $this->htmlResponse($moduleTemplate->renderContent());
    }
}

This should be migrated to:

.. code-block:: php

class MyController extends ActionController
{
    protected ModuleTemplateFactory $moduleTemplateFactory;
    protected IconFactory $iconFactory;
    protected PageRenderer $pageRenderer;

    public function __construct(
        ModuleTemplateFactory $moduleTemplateFactory,
        IconFactory $iconFactory,
        PageRenderer $pageRenderer
    ) {
        $this->moduleTemplateFactory = $moduleTemplateFactory;
        $this->iconFactory = $iconFactory;
        $this->pageRenderer = $pageRenderer;
    }

    public function myAction(): ResponseInterface
    {
        $moduleTemplate = $this->moduleTemplateFactory->create($this->request);
        $this->pageRenderer->loadRequireJsModule('Vendor/Extension/MyJsModule');
        $moduleTemplate->setContent($this->iconFactory->getIcon('some-icon', Icon::SIZE_SMALL)->render());
        return $this->htmlResponse($moduleTemplate->renderContent());
    }
}

.. index:: Backend, PHP-API, FullyScanned, ext:backend

@sabbelasichon sabbelasichon self-assigned this Oct 7, 2021
sabbelasichon added a commit that referenced this issue Jan 12, 2022
sabbelasichon added a commit that referenced this issue Jan 12, 2022
sabbelasichon added a commit that referenced this issue Jan 12, 2022
* Use PageRenderer and IconFactory directly

Resolves: #2672

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant