Development¶
The extension adds four custom enable fields:
cookiesdependent_iscookiesdependent
: Is cookie-dependent [tx_cookieconsentplus_iscookiesdependent]cookiesdependent_conditiontype
: Conditions evaluation type [tx_cookieconsentplus_conditiontype]cookiesdependent_statisticscondition
: Statistics cookies are [tx_cookieconsentplus_statisticscondition]cookiesdependent_marketingcondition
: Marketing cookies are [tx_cookieconsentplus_marketingcondition]
Add cookies-dependent enable fields in core table¶
To add, for example, the cookies-dependent enable fields to category record (sys_category table), in your extension,
add a new file Configuration/TCA/Override/sys_category.php
<?php
defined('TYPO3') or die();
// adds cookies-dependent enable fields to 'sys_category' model TCA and insert in 'access' sheet
$ll = 'LLL:EXT:cookieconsent_plus/Resources/Private/Language/locallang_db.xlf:ttcontent.';
$newFields = [
'tx_cookieconsentplus_iscookiesdependent' => [
'label' => $ll . 'tx_cookieconsentplus_iscookiesdependent',
'description' => $ll . 'tx_cookieconsentplus_iscookiesdependent.description',
'exclude' => 0,
'l10n_mode' => 'exclude',
'l10n_display' => 'defaultAsReadonly',
'config' => [
'type' => 'check',
],
'onChange' => 'reload',
],
'tx_cookieconsentplus_conditiontype' => [
'label' => $ll . 'tx_cookieconsentplus_conditiontype',
'description' => $ll . 'tx_cookieconsentplus_conditiontype.description',
'exclude' => 0,
'l10n_mode' => 'exclude',
'l10n_display' => 'defaultAsReadonly',
'displayCond' => 'FIELD:tx_cookieconsentplus_iscookiesdependent:=:1',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
$ll . 'tx_cookieconsentplus_conditiontype.showand',
'showand'
],
[
$ll . 'tx_cookieconsentplus_conditiontype.showor',
'showor'
],
],
],
],
'tx_cookieconsentplus_statisticscondition' => [
'label' => $ll . 'tx_cookieconsentplus_statisticscondition',
'description' => $ll . 'tx_cookieconsentplus_statisticscondition.description',
'exclude' => 0,
'l10n_mode' => 'exclude',
'l10n_display' => 'defaultAsReadonly',
'displayCond' => 'FIELD:tx_cookieconsentplus_iscookiesdependent:=:1',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
$ll . 'tx_cookieconsentplus_conditionvalue.anyvalue',
'anyvalue'
],
[
$ll . 'tx_cookieconsentplus_conditionvalue.denied',
'denied'
],
[
$ll . 'tx_cookieconsentplus_conditionvalue.accepted',
'accepted'
],
],
],
],
'tx_cookieconsentplus_marketingcondition' => [
'label' => $ll . 'tx_cookieconsentplus_marketingcondition',
'description' => $ll . 'tx_cookieconsentplus_marketingcondition.description',
'exclude' => 0,
'l10n_mode' => 'exclude',
'l10n_display' => 'defaultAsReadonly',
'displayCond' => 'FIELD:tx_cookieconsentplus_iscookiesdependent:=:1',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
$ll . 'tx_cookieconsentplus_conditionvalue.anyvalue',
'anyvalue'
],
[
$ll . 'tx_cookieconsentplus_conditionvalue.denied',
'denied'
],
[
$ll . 'tx_cookieconsentplus_conditionvalue.accepted',
'accepted'
],
],
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_category', $newFields);
$GLOBALS['TCA']['sys_category']['palettes']['cookiesdependent'] = [
'label' => $ll . 'tx_cookieconsentplus_iscookiesdependent.label',
'showitem' => 'tx_cookieconsentplus_iscookiesdependent,
--linebreak--, tx_cookieconsentplus_conditiontype,
--linebreak--, tx_cookieconsentplus_statisticscondition, tx_cookieconsentplus_marketingcondition',
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'sys_category',
'--palette--;;cookiesdependent',
'',
'after:hidden'
);
$GLOBALS['TCA']['sys_category']['ctrl']['enablecolumns']['cookiesdependent_iscookiesdependent'] = 'tx_cookieconsentplus_iscookiesdependent';
$GLOBALS['TCA']['sys_category']['ctrl']['enablecolumns']['cookiesdependent_conditiontype'] = 'tx_cookieconsentplus_conditiontype';
$GLOBALS['TCA']['sys_category']['ctrl']['enablecolumns']['cookiesdependent_statisticscondition'] = 'tx_cookieconsentplus_statisticscondition';
$GLOBALS['TCA']['sys_category']['ctrl']['enablecolumns']['cookiesdependent_marketingcondition'] = 'tx_cookieconsentplus_marketingcondition';
Then add fields to table in the database. In ext_tables.php
append
#
# Modifying 'sys_category' table
#
CREATE TABLE sys_category (
tx_cookieconsentplus_iscookiesdependent smallint(5) DEFAULT 0 NOT NULL,
tx_cookieconsentplus_conditiontype varchar(20) DEFAULT '' NOT NULL,
tx_cookieconsentplus_statisticscondition varchar(20) DEFAULT '' NOT NULL,
tx_cookieconsentplus_marketingcondition varchar(20) DEFAULT '' NOT NULL,
);
Add cookies-dependent enable fields in custom table¶
Just like in core table Add cookies-dependent enable fields in core table: simply change 'sys_category' table name with your table name.
Disable QueryBuilder cookies-dependent restriction, overall system¶
To disable QueryBuilder cookies-dependent restriction, you have to append in your ext_localconf.php
this line
<?php
declare(strict_types=1);
defined('TYPO3') or die();
// ...
// ...
// use PAD\CookieconsentPlus\Database\Query\Restriction\CookieRestriction;
$GLOBALS['TYPO3_CONF_VARS']['DB']['additionalQueryRestrictions'][CookieRestriction::class]['disabled'] = true;
How to remove cookies-dependent restriction in QueryBuilder¶
Cookies-dependent restriction can be removed just like built-in restrictions
<?php
declare(strict_types=1);
// ...
use PAD\CookieconsentPlus\Database\Query\Restriction\CookieRestriction;
// ...
class MyClass
{
// ...
public function myFunction(): void
{
// ...
$connection = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connection->getQueryBuilderForTable('tt_content');
$queryBuilder->getRestrictions()->removeByType(CookieRestriction::class);
// ...
}
}