[TYPO3-dev] FlashMessage TYPO3 7.6 Backend Hook

Pascal Querner – MSCG pascal.querner at mscg.de
Thu Nov 17 14:11:30 CET 2016


I debugged this somewhat. Here is what I learned so far:

My JSON Response from \TYPO3\CMS\Backend\Controller\SimpleDataHandlerController::processAjaxRequest
(called via Ajax Route "record_process" in AjaxDataHandler._call (typo3/sysext/backend/Resources/Public/JavaScript/AjaxDataHandler.js)
Looks like this

<script type="text/javascript">
/*<![CDATA[*/
	(function debug() {
		var message = 'somebigmessageIdontwanttoinclude',
			header = 'exec_SELECTquery',
			group = 'DB\u0020Error';
		if (top.TYPO3.DebugConsole) {
			top.TYPO3.DebugConsole.add(message, header, group);
		} else {
			var consoleMessage = [group, header, message].join(" | ");
			if (typeof console === "object" && typeof console.log === "function") {
				console.log(consoleMessage);
			}
		};
	})();
			
/*]]>*/
</script>{"redirect":"","messages":[{"title":"WARNING: MyWarning","message":"MyWarning","severity":2}],"hasErrors":true}

So it does get rendered correctly.
However, debugging why its not getting rendered, led me to 

AjaxDataHandler.deleteRecord (see file info above)
In the done callback function I do not see any of my debugging "console.logs" therefore I'll never enter there. (Therefore I have always the spinning icon, because its getting cleared in the callback function which I never enter)

HTTP Headers for info

Request URL:http://tejo.typo3.pq/typo3/index.php?ajaxID=%2Fajax%2Frecord%2Fprocess&ajaxToken=f6b052b324f07210708377e1de86b95fecd27f5d&cmd[tx_my_model][1][delete]=1
Request Method:GET
Status Code:200 OK

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate, sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Cookie:be_lastLoginProvider=1433416747; cb-enabled=accepted; XDEBUG_SESSION=pq-phpstorm; PHPSESSID=4vdgrjglf7aoa2tbfmfkalt6u5; be_typo_user=d79c89f8756405df626940409404950d
Host:xxxxxxxxxx
Pragma:no-cache
Referer:http://xxxxxxxxxxxx/typo3/index.php?M=web_list&moduleToken=0db77f8f216a5a9cfbcb0d36af5030d388eec02e&id=180
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.44 Safari/537.36
X-Requested-With:XMLHttpRequest


~Pascal

-----Ursprüngliche Nachricht-----
Von: typo3-dev-bounces at lists.typo3.org [mailto:typo3-dev-bounces at lists.typo3.org] Im Auftrag von Pascal Querner – MSCG
Gesendet: Donnerstag, 17. November 2016 10:49
An: typo3-dev at lists.typo3.org
Betreff: [TYPO3-dev] FlashMessage TYPO3 7.6 Backend Hook

Dieser Absender hat unsere Tests zur Betrugserkennung nicht bestanden und ist möglicherweise nicht der, der er zu sein scheint. Weitere Informationen über Spoofing unter "http://aka.ms/LearnAboutSpoofing".

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

_______________________________________________
TYPO3-dev mailing list
TYPO3-dev at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev



More information about the TYPO3-dev mailing list