Project

General

Profile

Actions

Bug #102922

closed

Memory limit php error when trying to add a button with addButton() in an event listener

Added by TimoF no-lastname-given 10 months ago. Updated 10 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2024-01-25
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

When I try to add a button in an event listener, I get a php memory limit error.
I am using this one: https://docs.typo3.org/m/typo3/reference-coreapi/12.4/en-us/ApiOverview/Events/Events/Backend/ModifyButtonBarEvent.html
This is the code. Everything is working till the line with addButton().

        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
        $buttonBar = $event->getButtonBar();
        $button = $buttonBar
            ->makeLinkButton()
            ->setHref('#')
            ->setTitle('TEST')
            ->setIcon($iconFactory->getIcon('actions-approve', Icon::SIZE_SMALL))
            ->setShowLabelText(true)
        ;
        $buttonBar->addButton($button, ButtonBar::BUTTON_POSITION_LEFT, 1);
        $event->setButtons($buttonBar->getButtons());
Actions #1

Updated by TimoF no-lastname-given 10 months ago

  • Subject changed from Memory limit php error when trying to add a button in an event listener to Memory limit php error when trying to add a button with addButton() in an event listener
Actions #2

Updated by Mathias Brodala 10 months ago

  • Description updated (diff)
Actions #3

Updated by Oliver Bartsch 10 months ago

  • Status changed from New to Needs Feedback

Hi, thanks for creating an issue.

The reason is the last line of your code snippet $event->setButtons($buttonBar->getButtons());. By calling $buttonBar->getButtons() you will dispatch the same event again, which leads to an endless loop. Could you please try removing the last line? This should resolve your issue.

Best, Oli

Actions #4

Updated by TimoF no-lastname-given 10 months ago

If i delete the last line, then no button is there.
But i found a working solution.
This works:

                $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
                $buttons = $event->getButtons();
                $buttons[ButtonBar::BUTTON_POSITION_LEFT][1][] = $event->getButtonBar()
                    ->makeLinkButton()
                    ->setTitle('Test')
                    ->setIcon($iconFactory->getIcon('actions-approve', Icon::SIZE_SMALL))
                    ->setShowLabelText(true)
                    ->setHref('#')
                $event->setButtons($buttons);

Actions #5

Updated by Oliver Bartsch 10 months ago

  • Status changed from Needs Feedback to Closed

Hi,

thanks for checking again. Because it seems that the issue is solved for you, I'll close this issue. In case you encounter similar problems or think this issue is not solved, please contact me or just create a new issue with reference to this one.

Best, Oli

Actions

Also available in: Atom PDF