Deprecation: #107824 - ButtonBar, Menu, and MenuRegistry make* methods deprecated
See forge#107824
Description
The factory methods in
Button for creating button instances, in
Menu for creating menu item instances, and in
Menu for
creating menu instances have been deprecated in favor of using the new
Component 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
Component in your controller and use its
create*
methods instead of
Button.
Before:
public function myAction(): ResponseInterface
{
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
$linkButton = $buttonBar->makeLinkButton()
->setHref($url)
->setTitle('My Link')
->setIcon($icon);
$buttonBar->addButton($linkButton);
// ...
}
After:
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 pre-configured button creation methods like
create,
create,
create,
and
create for common button patterns.
For the low-level
make method, use
General directly or the appropriate
Component method:
// 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:
// 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:
// 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);