Deprecation: #107823 - ButtonBar, Menu, and MenuRegistry make* methods deprecated
See forge#107823
Description
The factory methods in
\TYPO3\
for creating button instances, in
\TYPO3\ for creating menu item
instances, and in
\TYPO3\ for creating
menu instances have been deprecated in favor of using the new
\TYPO3\ class directly.
The following methods are now deprecated:
ButtonBar:: make Generic Button () ButtonBar:: make Input Button () ButtonBar:: make Split Button () ButtonBar:: make Drop Down Button () ButtonBar:: make Link Button () ButtonBar:: make Fully Rendered Button () ButtonBar:: make Shortcut Button () ButtonBar:: make Button () Menu::make Menu Item () MenuRegistry:: make Menu ()
Impact
Calling any of the deprecated
make* methods on
Button,
\Menu, or
Menu will trigger
a PHP deprecation notice.
The methods continue to work in TYPO3 v14 but will be removed in TYPO3 v15.
Affected installations
All extensions using
Button methods to create buttons,
Menu:: to create menu items, or
Menu to create menus are affected.
The extension scanner will report any usages.
Migration
Inject
\TYPO3\ in your
controller and use its
create* methods instead of
Button.
Before:
use Psr\Http\Message\ResponseInterface;
public function myAction(): ResponseInterface
{
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
$linkButton = $buttonBar->makeLinkButton()
->setHref($url)
->setTitle('My Link')
->setIcon($icon);
$buttonBar->addButton($linkButton);
// ...
}
After:
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\Components\ComponentFactory;
public function __construct(
protected readonly ComponentFactory $componentFactory,
) {}
public function myAction(): ResponseInterface
{
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
$linkButton = $this->componentFactory->createLinkButton()
->setHref($url)
->setTitle('My Link')
->setIcon($icon);
$buttonBar->addButton($linkButton);
// ...
}
Additionally, consider using the preconfigured button creation methods like
create,
create,
create,
create, and
create for common button patterns.
For the low-level
make method, use
General directly or the appropriate
Component method:
use TYPO3\CMS\Core\Utility\GeneralUtility;
// Before:
$button = $buttonBar->makeButton(MyCustomButton::class);
// After (option 1 - direct instantiation):
$button = GeneralUtility::makeInstance(MyCustomButton::class);
// After (option 2 - via factory if it's a standard button):
$button = $this->componentFactory->createLinkButton();
For
Menu::, use
Component:
use TYPO3\CMS\Backend\Template\Components\ComponentFactory;
// Before:
$menu = $menuRegistry->makeMenu();
$menuItem = $menu->makeMenuItem()
->setTitle('My View')
->setHref($url);
$menu->addMenuItem($menuItem);
// After:
public function __construct(
protected readonly ComponentFactory $componentFactory,
) {}
$menu = $this->componentFactory->createMenu();
$menuItem = $this->componentFactory->createMenuItem()
->setTitle('My View')
->setHref($url);
$menu->addMenuItem($menuItem);
For
Menu, use
Component:
use TYPO3\CMS\Backend\Template\Components\ComponentFactory;
// Before:
$menuRegistry = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry();
$menu = $menuRegistry->makeMenu();
$menu->setIdentifier('viewSelector')->setLabel('View');
// After:
public function __construct(
protected readonly ComponentFactory $componentFactory,
) {}
$menuRegistry = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry();
$menu = $this->componentFactory->createMenu();
$menu->setIdentifier('viewSelector')->setLabel('View');
Additionally, note that
Menu:: now returns
static
to support fluent interface patterns:
// Now possible with fluent interface:
$menu->addMenuItem($menuItem1)
->addMenuItem($menuItem2)
->addMenuItem($menuItem3);