Skip to content

Commit

Permalink
[!!!][TASK] Support of TYPO3 12
Browse files Browse the repository at this point in the history
Add support for TYPO3 11 & 12 and drop the support of TYPO3 10.
  • Loading branch information
georgringer authored Oct 7, 2022
1 parent 958cbd3 commit b0aa3ac
Show file tree
Hide file tree
Showing 37 changed files with 462 additions and 567 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ jobs:
fail-fast: false
matrix:
env:
- { php: 7.4, TYPO3_VERSION: ^10.4, TESTING_FRAMEWORK: ^6.5.0 }
- { php: 7.3, TYPO3_VERSION: ^10.4, TESTING_FRAMEWORK: ^6.5.0 }
- { php: 7.4, TYPO3_VERSION: ^11.0, TESTING_FRAMEWORK: ^6.6 }
- { php: 8.0, TYPO3_VERSION: ^11.0, TESTING_FRAMEWORK: ^6.6, experimental: true }
# - { php: 7.4, TYPO3_VERSION: "dev-master", TESTING_FRAMEWORK: ^6.5.0, experimental: true }
- { php: 7.4, TYPO3_VERSION: ^11.0, TESTING_FRAMEWORK: 7.x-dev }
- { php: 8.0, TYPO3_VERSION: ^11.0, TESTING_FRAMEWORK: 7.x-dev, experimental: true }
- { php: 8.1, TYPO3_VERSION: ^11.0, TESTING_FRAMEWORK: 7.x-dev, experimental: true }
- { php: 8.1, TYPO3_VERSION: ^12, TESTING_FRAMEWORK: 7.x-dev, experimental: true }

env: ${{ matrix.env }}

Expand Down
2 changes: 1 addition & 1 deletion Build/Local/FunctionalTests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-->
<phpunit
backupGlobals="true"
bootstrap="../../../../../../vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
bootstrap="../../../../../vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
Expand Down
35 changes: 12 additions & 23 deletions Classes/Controller/AddressController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;

Expand All @@ -51,9 +49,6 @@ public function initializeAction()
$this->extensionConfiguration = GeneralUtility::makeInstance(Settings::class);
}

/**
* @param \FriendsOfTYPO3\TtAddress\Domain\Model\Address $address
*/
public function showAction(Address $address = null)
{
if (is_a($address, Address::class) && ($this->settings['detail']['checkPidOfAddressRecord'] ?? false)) {
Expand All @@ -66,17 +61,19 @@ public function showAction(Address $address = null)
CacheUtility::addCacheTagsByAddressRecords([$address]);
}

$this->view->assign('address', $address);
$this->view->assignMultiple([
'address' => $address,
'contentObjectData' => $this->configurationManager->getContentObject()->data,
]);
return $this->htmlResponse();
}

/**
* Lists addresses by settings in waterfall principle.
* singleRecords take precedence over categories which take precedence over records from pages
*
* @param array $override Optional overriding demand
* @throws InvalidQueryException
*/
public function listAction(array $override = [])
public function listAction(?array $override = [])
{
$demand = $this->createDemandFromSettings();

Expand All @@ -102,12 +99,14 @@ public function listAction(array $override = [])

$this->view->assignMultiple([
'demand' => $demand,
'addresses' => $addresses
'addresses' => $addresses,
'contentObjectData' => $this->configurationManager->getContentObject()->data,
]);

CacheUtility::addCacheTagsByAddressRecords(
$addresses instanceof QueryResultInterface ? $addresses->toArray() : $addresses
);
return $this->htmlResponse();
}

/**
Expand All @@ -117,6 +116,7 @@ public function listAction(array $override = [])
*/
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
{
parent::injectConfigurationManager($configurationManager);
$this->configurationManager = $configurationManager;

// get the whole typoscript (_FRAMEWORK does not work anymore, don't know why)
Expand Down Expand Up @@ -153,7 +153,7 @@ public function injectConfigurationManager(ConfigurationManagerInterface $config

protected function createDemandFromSettings(): Demand
{
$demand = $this->objectManager->get(Demand::class);
$demand = new Demand();
$demand->setCategories((string)$this->settings['groups']);
$categoryCombination = (int)$this->settings['groupsCombination'] === 1 ? 'or' : 'and';
$demand->setCategoryCombination($categoryCombination);
Expand All @@ -170,7 +170,7 @@ protected function createDemandFromSettings(): Demand
return $demand;
}

protected function overrideDemand(Demand $demand, array $override): Demand
protected function overrideDemand(Demand $demand, array $override = []): Demand
{
$ignoredValues = ['singleRecords', 'pages'];
$ignoredValuesLower = array_map('strtolower', $ignoredValues);
Expand Down Expand Up @@ -203,17 +203,6 @@ public function injectAddressRepository(AddressRepository $addressRepository)
$this->addressRepository = $addressRepository;
}

/**
* Initializes the view before invoking an action method.
*
* @param ViewInterface $view The view to be initialized
*/
protected function initializeView(ViewInterface $view)
{
$view->assign('contentObjectData', $this->configurationManager->getContentObject()->data);
parent::initializeView($view);
}

/**
* Removes dots at the end of a configuration array
*
Expand Down
4 changes: 2 additions & 2 deletions Classes/Database/QueryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function getTreeList($id, $depth, $begin = 0): string
)
->orderBy('uid');

$statement = $queryBuilder->execute();
while ($row = $statement->fetch()) {
$statement = $queryBuilder->executeQuery();
while ($row = $statement->fetchAssociative()) {
if ($begin <= 0) {
$theList .= ',' . $row['uid'];
}
Expand Down
39 changes: 18 additions & 21 deletions Classes/Domain/Repository/AddressRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
use FriendsOfTYPO3\TtAddress\Domain\Model\Dto\Demand;
use FriendsOfTYPO3\TtAddress\Service\CategoryService;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser;
Expand All @@ -31,13 +30,7 @@ class AddressRepository extends Repository
*/
public function initializeObject()
{
$versionInformation = GeneralUtility::makeInstance(Typo3Version::class);
if ($versionInformation->getMajorVersion() >= 11) {
$this->defaultQuerySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
} else {
$this->defaultQuerySettings = $this->objectManager->get(Typo3QuerySettings::class);
}

$this->defaultQuerySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
$this->defaultQuerySettings->setRespectStoragePage(false);
}

Expand Down Expand Up @@ -77,19 +70,29 @@ protected function createDemandQuery(Demand $demand): QueryInterface
if ($categories) {
$categoryConstraints = $this->createCategoryConstraint($query, $categories, $demand->getIncludeSubCategories());
if ($demand->getCategoryCombination() === 'or') {
$constraints['categories'] = $query->logicalOr($categoryConstraints);
$constraints['categories'] = $query->logicalOr(...$categoryConstraints);
} else {
$constraints['categories'] = $query->logicalAnd($categoryConstraints);
$constraints['categories'] = $query->logicalAnd(...$categoryConstraints);
}
}

if ($demand->getIgnoreWithoutCoordinates()) {
$constraints['coordinatesLat'] = $query->logicalNot($query->equals('latitude', null));
$constraints['coordinatesLng'] = $query->logicalNot($query->equals('longitude', null));
$constraints['coordinatesLat'] = $query->logicalNot(
$query->logicalOr(
$query->equals('latitude', null),
$query->equals('latitude', 0.0)
)
);
$constraints['coordinatesLng'] = $query->logicalNot(
$query->logicalOr(
$query->equals('longitude', null),
$query->equals('longitude', 0.0)
)
);
}

if (!empty($constraints)) {
$query->matching($query->logicalAnd($constraints));
$query->matching($query->logicalAnd(...array_values($constraints)));
}
return $query;
}
Expand All @@ -104,13 +107,7 @@ protected function createDemandQuery(Demand $demand): QueryInterface
public function getSqlQuery(Demand $demand): string
{
$query = $this->createDemandQuery($demand);

$versionInformation = GeneralUtility::makeInstance(Typo3Version::class);
if ($versionInformation->getMajorVersion() >= 11) {
$queryParser = GeneralUtility::makeInstance(Typo3DbQueryParser::class);
} else {
$queryParser = $this->objectManager->get(Typo3DbQueryParser::class);
}
$queryParser = GeneralUtility::makeInstance(Typo3DbQueryParser::class);

$queryBuilder = $queryParser->convertQueryToDoctrineQueryBuilder($query);
$queryParameters = $queryBuilder->getParameters();
Expand Down Expand Up @@ -145,7 +142,7 @@ public function getAddressesByCustomSorting(Demand $demand)
$query->in('uid', $idList)
];

$query->matching($query->logicalAnd($constraints));
$query->matching($query->logicalAnd(...$constraints));
return $query->execute();
}

Expand Down
20 changes: 18 additions & 2 deletions Classes/FormEngine/FieldControl/LocationMapWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
* LICENSE.txt file that was distributed with this source code.
*/
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;

/**
* Adds a wizard for location selection via map
Expand Down Expand Up @@ -72,8 +76,20 @@ public function render(): array
$resultArray['linkAttributes']['data-copy'] = '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
$resultArray['stylesheetFiles'][] = 'EXT:tt_address/Resources/Public/Contrib/leaflet-core-1.4.0.css';
$resultArray['stylesheetFiles'][] = 'EXT:tt_address/Resources/Public/Backend/LocationMapWizard/leafletBackend.css';
$resultArray['requireJsModules'][] = 'TYPO3/CMS/TtAddress/leaflet-core-1.4.0';
$resultArray['requireJsModules'][] = 'TYPO3/CMS/TtAddress/LeafletBackend';

$versionInformation = GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion();
if ($versionInformation > 11) {
$id = StringUtility::getUniqueId('t3js-formengine-fieldcontrol-');
$resultArray['requireJsModules'][] = JavaScriptModuleInstruction::forRequireJS(
'TYPO3/CMS/TtAddress/leaflet-core-1.4.0'
)->instance($id);
$resultArray['requireJsModules'][] = JavaScriptModuleInstruction::forRequireJS(
'TYPO3/CMS/TtAddress/LeafletBackend'
)->instance($id);
} else {
$resultArray['requireJsModules'][] = 'TYPO3/CMS/TtAddress/leaflet-core-1.4.0';
$resultArray['requireJsModules'][] = 'TYPO3/CMS/TtAddress/LeafletBackend';
}

return $resultArray;
}
Expand Down
32 changes: 20 additions & 12 deletions Classes/Hooks/PageLayoutViewHook.php → ...s/FormEngine/TtAddressPreviewRenderer.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
<?php
declare(strict_types=1);

namespace FriendsOfTYPO3\TtAddress\Hooks;
namespace FriendsOfTYPO3\TtAddress\FormEngine;

/**
* This file is part of the "tt_address" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use Doctrine\DBAL\Connection;
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class PageLayoutViewHook implements PageLayoutViewDrawItemHookInterface
/**
* Improve the rendering of the plugin in page module
*/
class TtAddressPreviewRenderer extends StandardContentPreviewRenderer
{
protected $recordMapping = [
protected array $recordMapping = [
'singleRecords' => [
'table' => 'tt_address',
'multiValue' => true,
Expand All @@ -33,11 +42,10 @@ class PageLayoutViewHook implements PageLayoutViewDrawItemHookInterface
],
];

public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
protected function renderContentElementPreviewFromFluidTemplate(array $row): ?string
{
if ($row['list_type'] === 'ttaddress_listview' && $row['CType'] === 'list') {
$row = $this->enrichRow($row);
}
$row = $this->enrichRow($row);
return parent::renderContentElementPreviewFromFluidTemplate($row);
}

protected function enrichRow(array $row): array
Expand All @@ -59,7 +67,7 @@ protected function enrichRow(array $row): array
return $row;
}

protected function getRecords(string $table, string $idList)
protected function getRecords(string $table, string $idList): array
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
Expand All @@ -73,8 +81,8 @@ protected function getRecords(string $table, string $idList)
$queryBuilder->createNamedParameter(GeneralUtility::intExplode(',', $idList, true), Connection::PARAM_INT_ARRAY)
)
)
->execute()
->fetchAll();
->executeQuery()
->fetchAllAssociative();

foreach ($rows as &$row) {
$row['_computed']['title'] = BackendUtility::getRecordTitle($table, $row);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Hooks/Tca/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getAddressLabel(array &$params): void
foreach ($configuration as $fieldList) {
$label = [];
foreach ($fieldList as $field) {
if (isset($row[$field]) && !empty($row[$field])) {
if (isset($row['uid'], $row[$field]) && !empty($row[$field])) {
$label[] = BackendUtility::getProcessedValue('tt_address', $field, $row[$field], 0, false, 0, $row['uid']);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Classes/Service/CategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ protected function getChildrenCategoriesRecursive(string $idList, $counter = 0):
->where(
$queryBuilder->expr()->in('parent', $queryBuilder->createNamedParameter(explode(',', $idList), Connection::PARAM_INT_ARRAY))
)
->execute();
->executeQuery();

while ($row = $res->fetch()) {
while ($row = $res->fetchAssociative()) {
$counter++;
if ($counter > 10000) {
$this->timeTracker->setTSlogMessage('EXT:tt_address: one or more recursive categories where found');
Expand Down Expand Up @@ -118,8 +118,8 @@ protected function getUidListFromRecords(string $idList): string
->where(
$queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter(explode(',', $idList), Connection::PARAM_INT_ARRAY))
)
->execute()
->fetchAll();
->executeQuery()
->fetchAllAssociative();
foreach ($rows as $row) {
$list[] = $row['uid'];
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Service/GeocodeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function calculateCoordinatesForAllRecordsInTable($addWhereClause = ''):
->select('*')
->from($tableName)
->where(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->or(
$queryBuilder->expr()->isNull($latitudeField),
$queryBuilder->expr()->eq($latitudeField, $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq($latitudeField, 0.00000000000),
Expand All @@ -80,7 +80,7 @@ public function calculateCoordinatesForAllRecordsInTable($addWhereClause = ''):
if (!empty($addWhereClause)) {
$queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($addWhereClause));
}
$records = $queryBuilder->execute()->fetchAll();
$records = $queryBuilder->executeQuery()->fetchAllAssociative();
if (\count($records) > 0) {
foreach ($records as $record) {
$country = $record[$countryField];
Expand Down
16 changes: 16 additions & 0 deletions Configuration/Icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return [
'apps-pagetree-folder-contains-tt-address' => [
'provider' => \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
'source' => 'EXT:tt_address/Resources/Public/Icons/page-tree-module.svg',
],
'tt-address-plugin' => [
'provider' => \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
'source' => 'EXT:tt_address/Resources/Public/Icons/ContentElementWizard.svg',
],
'location-map-wizard' => [
'provider' => \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
'source' => 'EXT:tt_address/Resources/Public/Icons/actions-geo.svg',
],
];
Loading

0 comments on commit b0aa3ac

Please sign in to comment.