PHP code example of heimrichhannot / contao-versions

1. Go to this page and download the library: Download heimrichhannot/contao-versions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

heimrichhannot / contao-versions example snippets


use Contao\FrontendUser;
use Contao\Versions;
use HeimrichHannot\VersionsBundle\Version\VersionControl;

class MyCustomEntity 
{
    /** @var VersionControl */
    private $versionControl;

    protected function createVersion(int $id, FrontendUser $member): void
    {
        // Simple call
        $this->versionControl->createVersion('tl_my_custom_entity', $id);
        
        // Pass additional options
        $this->versionControl->createVersion('tl_my_custom_entity', $id, [
            'hideUser' => false,
            'additionalData' => [
                'memberid' => $member->id,
                'memberusername' => $member->username,
                'username' => 'FrontendUser',
                'userid' => 0,
            ],
            'instance' => new Versions('tl_my_custom_entity', $id),
        ]);
    }
}