PHP code example of webexmachina / contao-personal-data-manager

1. Go to this page and download the library: Download webexmachina/contao-personal-data-manager 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/ */

    

webexmachina / contao-personal-data-manager example snippets


 

use WEM\PersonalDataManagerBundle\Model\Traits\PersonalDataTrait as PDMTrait;

class MyModel
{
    use PDMTrait;
    /** @var array Fields to be managed by the Personal Data Manager */
    protected static $personalDataFieldsNames = ['myField'];
    /** @var array Default values for fields to be managed by the Personal Data Manager */
    protected static $personalDataFieldsDefaultValues = ['myField' => 'managed_by_pdm'];
    /** @var array Values for fields to be managed by the Personal Data Manager when anonymized */
    protected static $personalDataFieldsAnonymizedValues = ['myField' => 'Anonymized'];
    /** @var string Field to be used as pid by the Personal Data Manager */
    protected static $personalDataPidField = 'id';
    /** @var string Field to be used as email by the Personal Data Manager */
    protected static $personalDataEmailField = 'email';
    /** @var string ptable to be used by the Personal Data Manager */
    protected static $personalDataPtable = 'tl_my_table';




declare(strict_types=1);

namespace Your\Namespace;

use WEM\PersonalDataManagerBundle\Dca\Driver\PDMDCTableTrait;

class DC_Table extends \Contao\DC_Table
{
    use PDMDCTableTrait;
}

use Path\To\Your\Custom\Dca\Driver\DC_Table_Custom;

$GLOBALS['TL_DCA']['tl_my_table'] = [
    'config'=>[
        // ...
        'dataContainer' => DC_Table_Custom::class,
        'ondelete_callback' => [['wem.personal_data_manager.dca.config.callback.delete', '__invoke']],
        'onshow_callback' => [['wem.personal_data_manager.dca.config.callback.show', '__invoke']],
        'onsubmit_callback' => [['wem.personal_data_manager.dca.config.callback.submit', '__invoke']],
    ],
    'list'=>[
        'label' => [
            // ...
            'label_callback' => ['wem.personal_data_manager.dca.listing.callback.list_label_label_for_list', '__invoke'],
        ],
    ],
    'fields'=>[
        'myField'=>[
            // ...
            'load_callback' => [['wem.personal_data_manager.dca.field.callback.load', '__invoke']],
        ]
    ]
]




declare(strict_types=1);

namespace Your\Namespace\Dca\Field\Callback;

use WEM\PersonalDataManagerBundle\Dca\Field\Callback\Load as PdmCallback; // or Save

class Load
{
    /** @var WEM\PersonalDataManagerBundle\Dca\Field\Callback\Load */
    private $pdmCallback;
    /** @var string */
    private $frontendField;
    /** @var string */
    private $table;

    public function __construct(
        PdmCallback $pdmCallback,
        string $frontendField,
        string $table
    ) {
        $this->pdmCallback = $pdmCallback;
        $this->frontendField = $frontendField;
        $this->table = $table;

        $this->pdmCallback->setFrontendField($this->frontendField)->setTable($this->table);
    }

    public function __invoke()
    {
        return $this->pdmCallback->__invoke(...\func_get_args());
    }
}

$GLOBALS['TL_DCA']['tl_my_table']['fields']['myField']['load_callback'][] = ['your.bundle.dca.field.callback.load.tl_my_table.my_field', '__invoke'];