diff --git a/Classes/Controller/CookieController.php b/Classes/Controller/CookieController.php index f0ad966..831c18a 100644 --- a/Classes/Controller/CookieController.php +++ b/Classes/Controller/CookieController.php @@ -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, @@ -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); diff --git a/Classes/Domain/Model/Cookie.php b/Classes/Domain/Model/Cookie.php index fcc7492..f7099ba 100644 --- a/Classes/Domain/Model/Cookie.php +++ b/Classes/Domain/Model/Cookie.php @@ -42,7 +42,10 @@ class Cookie extends AbstractEntity * @var string */ protected $category = ''; - + /** + * @var string + */ + protected $categoryName; /** * @var string */ @@ -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 */ @@ -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; diff --git a/Classes/ViewHelpers/CookiesViewHelper.php b/Classes/ViewHelpers/CookiesViewHelper.php index 24396f6..298ea06 100644 --- a/Classes/ViewHelpers/CookiesViewHelper.php +++ b/Classes/ViewHelpers/CookiesViewHelper.php @@ -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); } } diff --git a/Configuration/TCA/tx_dpcookieconsent_domain_model_cookie.php b/Configuration/TCA/tx_dpcookieconsent_domain_model_cookie.php index 288ce24..22c6cd1 100644 --- a/Configuration/TCA/tx_dpcookieconsent_domain_model_cookie.php +++ b/Configuration/TCA/tx_dpcookieconsent_domain_model_cookie.php @@ -31,7 +31,7 @@ ], 'palettes' => [ 'type' => [ - 'showitem' => 'name, category' + 'showitem' => 'name, category, --linebreak--, category_name' ], 'dur' => [ 'showitem' => 'duration, duration_time' @@ -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', diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf index b9e3806..9f1a5cd 100644 --- a/Resources/Private/Language/locallang_db.xlf +++ b/Resources/Private/Language/locallang_db.xlf @@ -1,6 +1,6 @@ - +
@@ -12,6 +12,11 @@ Category + + + Alternative Category + + Required @@ -22,6 +27,10 @@ Marketing + + Custom + + Cookie description diff --git a/Resources/Private/Templates/Cookie/List.html b/Resources/Private/Templates/Cookie/List.html index b5c7fb1..158cd24 100644 --- a/Resources/Private/Templates/Cookie/List.html +++ b/Resources/Private/Templates/Cookie/List.html @@ -19,7 +19,7 @@ - + {groupItem.category} diff --git a/ext_emconf.php b/ext_emconf.php index 53b00aa..8ab76c1 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -25,6 +25,6 @@ 'suggests' => [], ], 'state' => 'beta', // stable - 'version' => '12.0.4' + 'version' => '12.1.0' ]; diff --git a/ext_tables.sql b/ext_tables.sql index 42fb89d..63ec72c 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -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,