Search code examples
typo3typo3-9.xtx-news

error because of missing object in signalslot (tx_news)


i wrote a signalslot extension for tx_news which extends the detailAction. The dispatcher works as expected when a news in detail view is called. But when the detail page is called without valid parameters for a existing news entry i get the following error:

Oops, an error occurred!
Argument 1 passed to .....\Slots\NewsControllerSlot::detailActionSlot() must be an instance of GeorgRinger\News\Domain\Model\News, null given

The error is easy to understand:

public function detailActionSlot(News $newsItem, $currentPage, $demand, $settings, $extendedVariables)

the first parameter $newsItem is missing.

But how can i avoid the error? Thanks!


Solution

  • David Bruchmann gave me a hint:

    public function detailActionSlot(News $newsItem = null, $currentPage, $demand, $settings, $extendedVariables)
    {
        if (is_object($newsItem)) { 
            // do stuff here
       }
    }
    

    works perfectly even the 404 is thrown.