[TYPO3-dev] FlashMessage TYPO3 7.6 Backend Hook

Pascal Querner – MSCG pascal.querner at mscg.de
Thu Nov 17 10:49:23 CET 2016


Hello Devs!

I’m struggling with having flashmessages visible on TYPO3 7.6.9 Backend which I add into the users Backend Session via Hook.

Idea: some Backend User wants to delete an object which has intact relations.
To prevent that I am hooking into „processCmdmap_preProcess“ and check if thats OK or not.
If it isnt OK I will override &$table variable, so no harm is done „after“ me.
That works well, but I’d like to show the user whats currently going on.

I want to inform the user about what happend via Flashmessage (prefer JS Flashmessage, because he’ll probably see it instantly instead of after page reload, because the Garbagebinicon is still spinning (as its still trying to delete something and takes ages for it.. but thats another story), but I cannot get it to work.

I see my message added to users BE session (be_session table in database) but its nowhere printed on the backend as far as I can tell.
I tried switching my users backend language (hoping it would fetch the messages from session table..), I tried loading another page where I often see flashmessages (TS Object Browser) etc.

Some code:

(All from within the Hook class)


$this->sendFlashMessage(
    LocalizationUtility::translate("object_deletion_refused.title", 'mxx'),
    LocalizationUtility::translate("object_deletion_refused.message", 'mxx'),
    FlashMessage::WARNING);


/**
* Sends a flash message to backend.
* Also logs it internally.
*
* @param string $messageHeader - Message Header
* @param string $messageBody   - Message body (actual information text)
* @param int    $severity
*/
protected function sendFlashMessage($messageHeader, $messageBody, $severity = FlashMessage::NOTICE)
{
    /** @var FlashMessage $message */
    $message = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
        htmlspecialchars($messageBody),
        htmlspecialchars($messageHeader),
        $severity,
        TRUE //store in session
    );

    $flashMessageService = $this->getFlashMessageService();
    $messageQueue        = $flashMessageService->getMessageQueueByIdentifier();
    $messageQueue->addMessage($message);
}



/**
 * Initialize and return FlashMessageService object
 *
 * @return FlashMessageService
 */
protected function getFlashMessageService()
{
    if (!$this->flashMessageService) {
        $this->flashMessageService = $this->getObjectManager()->get(
            FlashMessageService::class);
    }

    return $this->flashMessageService;
}


/**
 * Get ObjectManager instance
 *
 * @return ObjectManager
 */
protected function getObjectManager()
{
    if (!$this->objectManager) {
        /** @var $this ->objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
        $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
    }

    return $this->objectManager;
}



Best wishes,
Pascal Querner
Software-Developer




More information about the TYPO3-dev mailing list