Skip to content

Commit

Permalink
Entwicklung Extendes Cookie Banner
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkPersky committed Oct 30, 2023
1 parent e6c35b9 commit 9b215d9
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 13 deletions.
14 changes: 12 additions & 2 deletions Classes/Controller/CookieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public function listAction(): ResponseInterface
// get Cookies
$cookies = $this->cookieRepository->findByPid($flexFormData['settings']['startingpoint'], $flexFormData['settings']['recursive']);
// group cookies
$grouped = new ArrayObject([]);
$grouped = [];
foreach ($cookies as $cookie) {
$category = $cookie->getCategory();
$category = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('cookie.category.' . $cookie->getCategory(), 'dp_cookieconsent');
if ($cookie->getCategory() == 3) $category = $cookie->getCategoryName();

if (!isset($grouped[$category])) {
$grouped[$category] = new ArrayObject([
'category' => $category,
Expand All @@ -60,6 +62,14 @@ public function listAction(): ResponseInterface
$grouped[$category]['items'][] = $cookie;
}

usort($grouped, function ($a, $b){
if(strtolower($a['category']) == 'required') return -1;
if(strtolower($b['category']) == 'required') return 1;
return $a['category'] <=> $b['category'];
});

$grouped = new ArrayObject($grouped);

// update settings
$this->settings['base_uri'] = parse_url($this->request->getAttribute('normalizedParams')->getSiteUrl());
$this->view->assign('settings', $this->settings);
Expand Down
27 changes: 26 additions & 1 deletion Classes/Domain/Model/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class Cookie extends AbstractEntity
* @var string
*/
protected $category = '';

/**
* @var string
*/
protected $categoryName;
/**
* @var string
*/
Expand Down Expand Up @@ -254,6 +257,25 @@ public function setDescriptionLong(string $descriptionLong): void
$this->descriptionLong = $descriptionLong;
}

/**
* @return mixed
*/
public function getCategoryName(): mixed
{
return $this->categoryName;
}

/**
* @param string $categoryName
* @return void
*/
public function setCategoryName(string $categoryName): void
{
$this->categoryName = $categoryName;
}



/**
* @return string
*/
Expand Down Expand Up @@ -388,6 +410,9 @@ public function setSorting(int $sorting): void
public function getType(): string
{
switch ($this->category) {
case '3':
$type = strtolower($this->categoryName);
break;
case '1':
$type = 'statistics';
break;
Expand Down
22 changes: 16 additions & 6 deletions Classes/ViewHelpers/CookiesViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,37 @@ public function render()
$cobj = GeneralUtility::makeInstance(ContentObjectRenderer::class);

foreach ($cookies as $cookie) {
$category = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('cookie.category.'.$cookie->getCategory(), 'dp_cookieconsent');
$category = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('cookie.category.' . $cookie->getCategory(), 'dp_cookieconsent');

if ($cookie->getCategory() == 3) $category = $cookie->getCategoryName();
if (!$category) continue;

if (!isset($data[$category])) $data[$category] = ['name' => $category, 'cookies' => []];

$durationTime = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('cookie.duration_time.'.$cookie->getDurationTime(), 'dp_cookieconsent');
$durationTime = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('cookie.duration_time.' . $cookie->getDurationTime(), 'dp_cookieconsent');


$data[$category]['cookies'][] = [
$cookieConfig = [
'cookie_name' => $cookie->getName(),
'cookie_description_short' => $cookie->getDescription(),
'cookie_description' => $cookie->getDescriptionLong(),

'cookie_duration' => $cookie->getDuration(),
'cookie_duration_time' => $durationTime,
'cookie_duration_time' => $durationTime,

'cookie_vendor' => $cookie->getVendor(),
'cookie_vendor_link' => $cobj->typoLink_URL(['parameter' => $cookie->getVendorLink()]),
];

$data[$category]['cookies'][] = $cookieConfig;
}

return json_encode(array_values($data), $options);
$data = array_values($data);
usort($data, function ($a, $b){
if(strtolower($a['name']) == 'required') return -1;
if(strtolower($b['name']) == 'required') return 1;
return $a['name'] <=> $b['name'];
});

return json_encode($data, $options);
}
}
15 changes: 14 additions & 1 deletion Configuration/TCA/tx_dpcookieconsent_domain_model_cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
'palettes' => [
'type' => [
'showitem' => 'name, category'
'showitem' => 'name, category, --linebreak--, category_name'
],
'dur' => [
'showitem' => 'duration, duration_time'
Expand Down Expand Up @@ -120,10 +120,23 @@
['LLL:EXT:dp_cookieconsent/Resources/Private/Language/locallang_db.xlf:tx_dpcookieconsent_domain_model_cookie.category.0', 0],
['LLL:EXT:dp_cookieconsent/Resources/Private/Language/locallang_db.xlf:tx_dpcookieconsent_domain_model_cookie.category.1', 1],
['LLL:EXT:dp_cookieconsent/Resources/Private/Language/locallang_db.xlf:tx_dpcookieconsent_domain_model_cookie.category.2', 2],
['LLL:EXT:dp_cookieconsent/Resources/Private/Language/locallang_db.xlf:tx_dpcookieconsent_domain_model_cookie.category.3', 3],
],
],
'onChange' => 'reload'
],

'category_name' => [
'exclude' => true,
'label' => 'LLL:EXT:dp_cookieconsent/Resources/Private/Language/locallang_db.xlf:tx_dpcookieconsent_domain_model_cookie.category_name',
'config' => [
'type' => 'input',
'size' => 75,
'eval' => 'trim'
],
'displayCond' => 'FIELD:category:=:3'
],

'description' => [
'exclude' => true,
'label' => 'LLL:EXT:dp_cookieconsent/Resources/Private/Language/locallang_db.xlf:tx_dpcookieconsent_domain_model_cookie.description',
Expand Down
11 changes: 10 additions & 1 deletion Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2023-25-10T13:50:10Z" product-name="cookieconsent">
<file source-language="en" datatype="plaintext" original="messages" date="2023-30-10T14:50:10Z" product-name="cookieconsent">
<header/>
<body>
<trans-unit id="tx_dpcookieconsent_domain_model_cookie">
Expand All @@ -12,6 +12,11 @@
<trans-unit id="tx_dpcookieconsent_domain_model_cookie.category">
<source>Category</source>
</trans-unit>

<trans-unit id="tx_dpcookieconsent_domain_model_cookie.category_name">
<source>Alternative Category</source>
</trans-unit>

<trans-unit id="tx_dpcookieconsent_domain_model_cookie.category.0">
<source>Required</source>
</trans-unit>
Expand All @@ -22,6 +27,10 @@
<source>Marketing</source>
</trans-unit>

<trans-unit id="tx_dpcookieconsent_domain_model_cookie.category.3">
<source>Custom</source>
</trans-unit>

<trans-unit id="tx_dpcookieconsent_domain_model_cookie.description_long">
<source>Cookie description</source>
</trans-unit>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Cookie/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<thead class="border-top-0">
<tr class="caption">
<th colspan="4" class="{f:if(condition:groupIterator.isFirst, then:'', else:'pt-4')}">
<f:translate key="cookie.category.{groupItem.category}"/>
<f:format.raw>{groupItem.category}</f:format.raw>
</th>
</tr>
<tr class="table-dark">
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
'suggests' => [],
],
'state' => 'beta', // stable
'version' => '12.0.4'
'version' => '12.1.0'
];

1 change: 1 addition & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CREATE TABLE tx_dpcookieconsent_domain_model_cookie
pid int(11) DEFAULT '0' NOT NULL,

category varchar(255) DEFAULT '' NOT NULL,
category_name varchar(255) DEFAULT '' NOT NULL,
name varchar(255) DEFAULT '' NOT NULL,
description varchar(255) DEFAULT '' NOT NULL,
description_long text,
Expand Down

0 comments on commit 9b215d9

Please sign in to comment.