TYPO3 Extbase - how to use core Signal/Slots -


i have working extbase extension in typo3 v6.2, stores products. want learn using signal/slot (extbase variant of hooks). wonder why example don't work. when update product in list module in typo3 backend, saves correctly no message appears.

file typo3conf/ext/myext/ext_localconf.php

$signalslotdispatcher = \typo3\cms\core\utility\generalutility::makeinstance( 'typo3\\cms\\extbase\\signalslot\\dispatcher' ); $signalslotdispatcher->connect(     'typo3\\cms\\extbase\\persistence\\generic\\backend',     'afterupdateobject',     'myvendor\\myext\\service\\signalservice',         'myafterupdate',     false ); 

file typo3conf/ext/myext/service/signalservice.php

namespace myvendor\myext\service;  class signalservice implements \typo3\cms\core\singletoninterface {      /**      * @param  \typo3\cms\extbase\domainobject\domainobjectinterface $object      */     public function myafterupdate(\typo3\cms\extbase\domainobject\domainobjectinterface $object){              if ($object instanceof \myvendor\myext\domain\model\products) {                  // check if come point                  \typo3\cms\extbase\utility\debuggerutility::var_dump('successfully hooked - slot.');                 die();              }         }  } 


update 15.06.2015
hint patrick lobacher remarked, cannot use die() in context. instead, should write logfile. don't work me either. no file written:

file typo3conf/ext/myext/ext_localconf.php

/**   * @var \typo3\cms\extbase\signalslot\dispatcher $signalslotdispatcher   * */ $signalslotdispatcher = \typo3\cms\core\utility\generalutility::makeinstance('typo3\\cms\\extbase\\object\\objectmanager')->get('typo3\\cms\\extbase\\signalslot\\dispatcher'); $signalslotdispatcher->connect(    'typo3\\cms\\extbase\\persistence\\generic\\backend',    'afterupdateobject',    function ($payload) {         $logfile = "fileadmin/test/logfile.txt";         $handle = fopen($logfile, "a+");        fwrite ($handle, 'hi. written ext_localconf.php. ' . time());        fclose ($handle);     }); 


update 29.06.2015
on https://forge.typo3.org/issues/61979 francois wrote, "object manager may used in extbase context, not in ext_localconf.php". however, given answer don't work me. perhaps helps else.

currently there no official documentation, in issue can find unofficial documentation: https://forge.typo3.org/issues/59089

the problem using signal slots of extbase in list module. in 6.2 list module not implemented using extbase. there no slots can use. instead need follow old, documented, way using hooks: https://docs.typo3.org/typo3cms/coreapireference/apioverview/hooks/concept/index.html

in case, following code should work entry point:

ext_localconf.php:

$globals['typo3_conf_vars']['sc_options']['t3lib/class.t3lib_tcemain.php']['processdatamapclass'][$_extkey]     = 'vendor\extname\hook\datamaphook'; 

there configure class use hook t3lib_tcemain old classname before typo3 6.2 handling more data list view.

inside of class can implement code done you:

classes/hook/datamaphook.php:

<?php namespace vendor\extname\hook;  /**  * hook process updated records.  *  * @author daniel siepmann <d.siepmann@web-vision.de>  */ class datamaphook {      /**     * hook add latitude , longitude locations.     *     * @param string $action action perform, e.g. 'update'.     * @param string $table table affected action, e.g. 'fe_users'.     * @param int $uid uid of record affected action.     * @param array $modifiedfields modified fields of record.     *     * @return void     */     public function processdatamap_postprocessfieldarray(         $action, $table, $uid, array &$modifiedfields     ) {         if(!$this->executehook($table, $action)) {             return;         }          // check if come point          \typo3\cms\extbase\utility\debuggerutility::var_dump('successfully hooked - slot.');         die();     }      /**     * check whether execute hook or not.     *     * @param string $table     * @param string $action     * @param array $modifiedfields     *     * @return bool     */     protected function executehook($table, $action)     {         // not process if foreign table, unintended action,         // or fields changed explicitly.         if ($table !== 'tx_extname_domain_model_modelname' || $action !== 'update') {             return false;         }          return false;     } } 

and yes, can use die in context, debugging , such. typo3 iterate on configured hooks , call methods. nothing fancy here. parameters defined implementation , can work them.

in above example there 1 check execute hook if table , action matches. code called many reasons make sure whitelist it, execute in environments know about. security , performance reasons.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -