Issue Bug Closed

#100911Custom MenuProcessor creates kind of singleton

Philipp Schlosser 05/23/23, 13:16 updated 07/09/24, 14:15

Description

If you implement a custom MenuProcessor, for every new menuProcessor you define in typoscript, the same instance will be used.

for example

page = PAGE
page {
    10 = FLUIDTEMPLATE
    10 {
        dataProcessing {
            10 = MyVendor\MyExtension\DataProcessing\CustomMenuProcessor
            10 {
                special = directory
                special.value = 10 # should show every child page from page 10
                as = menuOne
            }
            20 = MyVendor\MyExtension\DataProcessing\CustomMenuProcessor
            20 {
                special = directory
                special.value = 20 # should show every child page from page 20
                as = menuTwo
            }
        }
    }
}

In this example “menuOne” should contain every child page from page 10. “menuTwo” should container every child page from page 20 but does contain pages from 10.

Another example:
Use TS Config from above and implement a counter property in your custom MenuProcessor.

namespace MyVendor\MyExtension\DataProcessing;

class CustomMenuProcessor implements \TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface {
    protected $counter = 0;
    /**
     * @param ContentObjectRenderer $cObj
     * @param array $contentObjectConfiguration
     * @param array $processorConfiguration
     * @param array $processedData
     * @return array
     */
    public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData): array
    {
        $this->counter ++;
        \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->counter);
        return $processedData;
    }
}

The example above should print 1 and 1, but does 1 and 2.

Reviews 2