Skip to content

Commit

Permalink
[FEATURE] Let it hide on provided pages
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Mar 12, 2020
1 parent 584aa16 commit 390bfc7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Classes/Hooks/PageRendererHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -84,6 +85,13 @@ protected function createTranslations(array $siteConfiguration): void
}' . $privacyLinkConfiguration . '
};
', true);

$hiddenOnPages = $siteConfiguration['klaro_hidden_on_pages'] ?? '';
if ($hiddenOnPages && $pageId = $this->getCurrentPageId()) {
if (in_array($pageId, GeneralUtility::intExplode(',', $hiddenOnPages), true)) {
$this->pageRenderer->addCssInlineBlock('hideKlaro', '#klaro {display:none !important;}');
}
}
}

protected function includeLanguageFileForInline($fileRef)
Expand Down Expand Up @@ -171,6 +179,16 @@ protected function getCurrentSite(): ?SiteInterface
return null;
}

protected function getCurrentPageId(): int
{
$pageId = 0;
$pageArguments = $GLOBALS['TYPO3_REQUEST']->getAttribute('routing');
if ($pageArguments instanceof PageArguments) {
$pageId = $pageArguments->getPageId();
}
return $pageId;
}

/**
* @return TypoScriptFrontendController
*/
Expand Down
12 changes: 10 additions & 2 deletions Configuration/SiteConfiguration/Overrides/sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function ($table) {
];
$GLOBALS['SiteConfiguration'][$table]['columns']['klaro_must_consent'] = [
'label' => $lll . 'site.configuration.must_consent',
'description' => $lll . 'site.configuration.must_consent.description',
'config' => [
'description' => $lll . 'site.configuration.must_consent.description',
'type' => 'check',
'default'
],
Expand All @@ -54,8 +54,16 @@ function ($table) {
'placeholder' => 'EXT:klaro/Resources/Public/Klaro/klaro-0.2.15.js'
],
];
$GLOBALS['SiteConfiguration'][$table]['columns']['klaro_hidden_on_pages'] = [
'label' => $lll . 'site.configuration.hidden_on_pages',
'description' => $lll . 'site.configuration.hidden_on_pages.description',
'config' => [
'type' => 'input',
'placeholder' => '12,34'
],
];
$GLOBALS['SiteConfiguration'][$table]['types']['0']['showitem'] .= '
,--div--;' . $lll . 'site.configuration.tab, klaro_enable,klaro_privacy_page,klaro_configuration_file,klaro_language_file,klaro_must_consent,klaro_core_js,klaro_style_prefix
,--div--;' . $lll . 'site.configuration.tab, klaro_enable,klaro_privacy_page,klaro_configuration_file,klaro_language_file,klaro_hidden_on_pages,klaro_must_consent,klaro_core_js,klaro_style_prefix
';
},
'site'
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Language/Configuration.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<trans-unit id="site.configuration.must_consent.description">
<source>Force user for consent</source>
</trans-unit>
<trans-unit id="site.configuration.hidden_on_pages">
<source>Comma separated list of pages where klaro is hidden</source>
</trans-unit>
<trans-unit id="site.configuration.hidden_on_pages.description">
<source>Useful/Required for pages like imprint and legal information</source>
</trans-unit>
<trans-unit id="site.configuration.tab">
<source>Klaro Cookie Settings</source>
</trans-unit>
Expand Down

0 comments on commit 390bfc7

Please sign in to comment.