diff --git a/Classes/Controller/CookieBarAdministrationController.php b/Classes/Controller/CookieBarAdministrationController.php index 8bf932a..c34448a 100644 --- a/Classes/Controller/CookieBarAdministrationController.php +++ b/Classes/Controller/CookieBarAdministrationController.php @@ -26,7 +26,9 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Pixelant\PxaCookieBar\Domain\Repository\CookieWarningRepository; use Pixelant\PxaCookieBar\Utility\BackendTranslateUtility; +use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Template\Components\ButtonBar; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\View\BackendTemplateView; @@ -34,6 +36,7 @@ use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Messaging\FlashMessage; +use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; @@ -62,10 +65,17 @@ class CookieBarAdministrationController extends ActionController /** * @var \Pixelant\PxaCookieBar\Domain\Repository\CookieWarningRepository - * @inject */ protected $cookieWarningRepository = null; + /** + * @param CookieWarningRepository $cookieWarningRepository + */ + public function injectCookieWarningRepository(CookieWarningRepository $cookieWarningRepository) + { + $this->cookieWarningRepository = $cookieWarningRepository; + } + /** * Array of db row of current selected page * @@ -153,7 +163,7 @@ protected function initialize() public function indexAction() { if ($this->pageUid) { - $countRecords = $this->cookieWarningRepository->countByPid($this->pageUid); + $countRecords = $this->cookieWarningRepository->countByPidRespectDisabled($this->pageUid); if ($countRecords > 1) { $this->addFlashMessage( @@ -164,6 +174,10 @@ public function indexAction() } if ($countRecords > 0) { $this->view->assign('htmlDbList', $this->getDbListHTML()); + if (version_compare(TYPO3_version, '9.0', '>')) { + // Need to add labels manually + $this->includeLanguageFile('EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf'); + } } else { $this->view->assign('newRecordUrl', $this->buildNewCookieWarningUrl()); } @@ -219,8 +233,6 @@ protected function getDbListHTML(): string $dbList->displayFields = []; $dbList->dontShowClipControlPanels = true; $dbList->counter++; - $dbList->newWizards = false; - $dbList->MOD_MENU = ['bigControlPanel' => '', 'clipBoard' => '', 'localization' => '']; $pointer = MathUtility::forceIntegerInRange(GeneralUtility::_GP('pointer'), 0); $dbList->start( @@ -241,7 +253,7 @@ protected function getDbListHTML(): string */ protected function buildNewCookieWarningUrl(): string { - $url = BackendUtility::getModuleUrl( + $url = (string)GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute( 'record_edit', [ 'edit[tx_pxacookiebar_domain_model_cookiewarning][' . $this->pageUid . ']' => 'new', @@ -252,6 +264,19 @@ protected function buildNewCookieWarningUrl(): string return $url; } + /** + * Add js labels from file + * + * @param $file + * @return void + */ + protected function includeLanguageFile(string $file) + { + $this->getPageRenderer()->addInlineLanguageLabelFile( + GeneralUtility::getFileAbsFileName($file) + ); + } + /** * Check if it's allowed to create new cookie warnings * @@ -259,7 +284,18 @@ protected function buildNewCookieWarningUrl(): string */ protected function isNewCookieBarAllowed(): bool { - return $this->pageUid !== 0 && ($this->cookieWarningRepository->countByPid($this->pageUid) === 0); + return $this->pageUid !== 0 + && ($this->cookieWarningRepository->countByPidRespectDisabled($this->pageUid) === 0); + } + + /** + * Wrapper for class + * + * @return PageRenderer + */ + protected function getPageRenderer(): PageRenderer + { + return GeneralUtility::makeInstance(PageRenderer::class); } /** diff --git a/Classes/Controller/CookieWarningController.php b/Classes/Controller/CookieWarningController.php index 4a9dbcb..78666fe 100644 --- a/Classes/Controller/CookieWarningController.php +++ b/Classes/Controller/CookieWarningController.php @@ -26,6 +26,7 @@ ***************************************************************/ use Pixelant\PxaCookieBar\Domain\Model\CookieWarning; +use Pixelant\PxaCookieBar\Domain\Repository\CookieWarningRepository; use Pixelant\PxaCookieBar\Utility\CookieUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; @@ -41,10 +42,17 @@ class CookieWarningController extends ActionController /** * @var \Pixelant\PxaCookieBar\Domain\Repository\CookieWarningRepository - * @inject */ protected $cookieWarningRepository; + /** + * @param CookieWarningRepository $cookieWarningRepository + */ + public function injectCookieWarningRepository(CookieWarningRepository $cookieWarningRepository) + { + $this->cookieWarningRepository = $cookieWarningRepository; + } + /** * Render message * diff --git a/Classes/Domain/Repository/CookieWarningRepository.php b/Classes/Domain/Repository/CookieWarningRepository.php index 549b7c9..032cdbd 100644 --- a/Classes/Domain/Repository/CookieWarningRepository.php +++ b/Classes/Domain/Repository/CookieWarningRepository.php @@ -76,10 +76,14 @@ public function findByPid(int $pid) * @param int $pid * @return int */ - public function countByPid(int $pid): int + public function countByPidRespectDisabled(int $pid): int { $query = $this->createQuery(); + $query->getQuerySettings() + ->setIgnoreEnableFields(true) + ->setEnableFieldsToBeIgnored(['disable']); + $query->matching( $query->equals('pid', $pid) ); diff --git a/Configuration/TCA/tx_pxacookiebar_domain_model_cookiewarning.php b/Configuration/TCA/tx_pxacookiebar_domain_model_cookiewarning.php index f790798..ee2cead 100644 --- a/Configuration/TCA/tx_pxacookiebar_domain_model_cookiewarning.php +++ b/Configuration/TCA/tx_pxacookiebar_domain_model_cookiewarning.php @@ -3,6 +3,11 @@ $ll = 'LLL:EXT:pxa_cookie_bar/Resources/Private/Language/locallang_db.xlf:'; +if (version_compare(TYPO3_version, '9.0', '>')) { + $llCore = 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:'; +} else { + $llCore = 'LLL:EXT:lang/locallang_general.xlf:'; +} return [ 'ctrl' => [ 'title' => $ll . 'tx_pxacookiebar_domain_model_cookiewarning', @@ -42,14 +47,14 @@ 'columns' => [ 'sys_language_uid' => [ 'exclude' => 1, - 'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language', + 'label' => $llCore . 'LGL.language', 'config' => [ 'type' => 'select', 'renderType' => 'selectSingle', 'special' => 'languages', 'items' => [ [ - 'LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', + $llCore . 'LGL.allLanguages', -1, 'flags-multiple' ], @@ -60,7 +65,7 @@ 'l10n_parent' => [ 'displayCond' => 'FIELD:sys_language_uid:>:0', 'exclude' => 1, - 'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.l18n_parent', + 'label' => $llCore . 'LGL.l18n_parent', 'config' => [ 'type' => 'select', 'renderType' => 'selectSingle', @@ -79,14 +84,13 @@ ], 'hidden' => [ 'exclude' => 1, - 'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.hidden', + 'label' => $llCore . 'LGL.hidden', 'config' => [ 'type' => 'check' ] ], 'starttime' => [ 'exclude' => 1, - 'l10n_mode' => 'mergeIfNotBlank', 'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:starttime_formlabel', 'config' => [ 'type' => 'input', @@ -101,7 +105,6 @@ ], 'endtime' => [ 'exclude' => 1, - 'l10n_mode' => 'mergeIfNotBlank', 'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:endtime_formlabel', 'config' => [ 'type' => 'input', @@ -148,8 +151,8 @@ 'label' => $ll . 'tx_pxacookiebar_domain_model_cookiewarning.link_target', 'config' => [ 'type' => 'input', - 'size' => '15', - 'max' => '256', + 'size' => 15, + 'max' => 256, 'eval' => 'trim', 'renderType' => 'inputLink', 'softref' => 'typolink' diff --git a/Tests/Unit/Controller/CookieBarAdministrationControllerTest.php b/Tests/Unit/Controller/CookieBarAdministrationControllerTest.php index 6971969..84a9a46 100644 --- a/Tests/Unit/Controller/CookieBarAdministrationControllerTest.php +++ b/Tests/Unit/Controller/CookieBarAdministrationControllerTest.php @@ -49,10 +49,10 @@ public function ifCookieBarExistNewCookieBarIsNotAllowed() $pageUid = 123; $this->subject->_set('pageUid', $pageUid); - $mockedRepository = $this->createPartialMock(CookieWarningRepository::class, ['countByPid']); + $mockedRepository = $this->createPartialMock(CookieWarningRepository::class, ['countByPidRespectDisabled']); $mockedRepository ->expects($this->once()) - ->method('countByPid') + ->method('countByPidRespectDisabled') ->with($pageUid) ->will($this->returnValue(1)); @@ -69,10 +69,10 @@ public function itsPossibleToCreateNewCookieBarIfPageIsSetAndNoRecordsFound() $pageUid = 123; $this->subject->_set('pageUid', $pageUid); - $mockedRepository = $this->createPartialMock(CookieWarningRepository::class, ['countByPid']); + $mockedRepository = $this->createPartialMock(CookieWarningRepository::class, ['countByPidRespectDisabled']); $mockedRepository ->expects($this->once()) - ->method('countByPid') + ->method('countByPidRespectDisabled') ->with($pageUid) ->will($this->returnValue(0)); diff --git a/composer.json b/composer.json index 45c9874..b664f56 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "type": "typo3-cms-extension", "license": "GPL-2.0+", "require": { - "typo3/minimal": "^9.3" + "typo3/cms-core": "^8.7 || ^9.3", + "php": ">=7.0" }, "require-dev": { "squizlabs/php_codesniffer": "^3.2", diff --git a/ext_emconf.php b/ext_emconf.php index 30987b8..f11ff7d 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -18,10 +18,10 @@ 'author_email' => 'andriy@pixelant.se', 'author_company' => 'Pixelant', 'clearCacheOnLoad' => false, - 'version' => '2.0.3', + 'version' => '2.1.0', 'constraints' => [ 'depends' => [ - 'typo3' => '8.7.0-8.9.99' + 'typo3' => '8.7.0-9.9.99' ], 'conflicts' => [], 'suggests' => [],