Skip to content

Commit

Permalink
Merge pull request #12 from pixelant/typo9
Browse files Browse the repository at this point in the history
[TASK] support of TYPO3 9.4
  • Loading branch information
anjeylink committed Aug 6, 2018
2 parents dd369ce + 4e4795b commit d4c97d5
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 23 deletions.
48 changes: 42 additions & 6 deletions Classes/Controller/CookieBarAdministrationController.php
Expand Up @@ -26,14 +26,17 @@
* 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;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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(
Expand All @@ -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());
}
Expand Down Expand Up @@ -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(
Expand All @@ -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',
Expand All @@ -252,14 +264,38 @@ 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
*
* @return bool
*/
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);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion Classes/Controller/CookieWarningController.php
Expand Up @@ -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;

Expand All @@ -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
*
Expand Down
6 changes: 5 additions & 1 deletion Classes/Domain/Repository/CookieWarningRepository.php
Expand Up @@ -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)
);
Expand Down
19 changes: 11 additions & 8 deletions Configuration/TCA/tx_pxacookiebar_domain_model_cookiewarning.php
Expand Up @@ -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',
Expand Down Expand Up @@ -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'
],
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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'
Expand Down
Expand Up @@ -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));

Expand All @@ -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));

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions ext_emconf.php
Expand Up @@ -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' => [],
Expand Down

0 comments on commit d4c97d5

Please sign in to comment.