TYPO3 Extbase individual code on backend-deletion of an object

前端 未结 2 1753
春和景丽
春和景丽 2021-01-14 08:03

I would like to execute some individual code when one of my Extbase domain objects is deleted from the list view in TYPO3 backend.

Thought that it could / would work

相关标签:
2条回答
  • 2021-01-14 08:30

    In addition to biesiors answer I want to point out, that there is also a signalSlot for this. So you can rather register on that signal than hooking into tcemain.

    in your ext_localconf.php put:

    $signalSlotDispatcher =
                \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
    $signalSlotDispatcher->connect(
        'TYPO3\CMS\Extbase\Persistence\Generic\Backend',
        'afterRemoveObject',
        'Vendor\MxExtension\Slots\MyAfterRemoveObjectSlot',
        'myAfterRemoveObjectMethod'
    );
    

    So in your Slot you have this PHP file:

    namespace Vendor\MxExtension\Slots;
    class MyAfterRemoveObjectSlot {
        public function myAfterRemoveObjectMethod($object) {
             // do something
        }
    }
    

    Note thet $object will be the $object that was just removed from the DB.

    For more information, see https://usetypo3.com/signals-and-hooks-in-typo3.html

    0 讨论(0)
  • 2021-01-14 08:39

    List view uses TCEmain hooks during its operations, so you can use one of them to intersect delete action, i.e.: processCmdmap_deleteAction

    1. Register your hooks class in typo3conf/ext/your_ext/ext_tables.php

      $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][] = 'VENDORNAME\\YourExt\\Hooks\\ProcessCmdmap';
      
    2. Create a class with valid namespace and path (according to previous step)
      file: typo3conf/ext/your_ext/Classes/Hooks/ProcessCmdmap.php

      <?php
      namespace VENDORNAME\YourExt\Hooks;
      
      class ProcessCmdmap {
         /**
          * hook that is called when an element shall get deleted
          *
          * @param string $table the table of the record
          * @param integer $id the ID of the record
          * @param array $record The accordant database record
          * @param boolean $recordWasDeleted can be set so that other hooks or
          * @param DataHandler $tcemainObj reference to the main tcemain object
          * @return   void
          */
          function processCmdmap_postProcess($command, $table, $id, $value, $dataHandler) {
              if ($command == 'delete' && $table == 'tx_yourext_domain_model_something') {
                  // Perform something before real delete
                  // You don't need to delete the record here it will be deleted by CMD after the hook
              }
          }
      } 
      
    3. Don't forget to clear system cache after registering new hook's class

    0 讨论(0)
提交回复
热议问题