Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 903 Bytes

Undo.md

File metadata and controls

41 lines (31 loc) · 903 Bytes

Undo component

This component class is designed to help restore the data using the Restore module (tl_undo).

Usage

First, you must register an ondelete_callback in your DCA:

// DCA
$GLOBALS['TL_DCA']['tl_table']['config']['ondelete_callback'][] = [MyListener::class, 'onDeleteCallback'];

// Listener
use Codefog\HasteBundle\UndoManager;
use Contao\DataContainer;

class MyListener
{
    public function onDeleteCallback(DataContainer $dc, int $undoId): void
    {
        $this->undoManager->add($undoId, 'my_data', ['foo' => 'bar']);
    }
}

Then, to manually restore the data you have to subscribe to the event listener:

use Codefog\HasteBundle\Event\UndoEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener]
class MyListener
{
    public function __invoke(UndoEvent $event)
    {
        // … do your magic …
    }
}