Initial commit - Typo3 11.5.41
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
namespace FriendsOfTYPO3\TtAddress\FormEngine\FieldControl;
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
*/
|
||||
class LocationMapWizard extends AbstractNode
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function render(): array
|
||||
{
|
||||
$row = $this->data['databaseRow'];
|
||||
$paramArray = $this->data['parameterArray'];
|
||||
$resultArray = $this->initializeResultArray();
|
||||
|
||||
$nameLongitude = $paramArray['itemFormElName'];
|
||||
$nameLatitude = str_replace('longitude', 'latitude', $nameLongitude);
|
||||
$nameLatitudeActive = str_replace('data', 'control[active]', $nameLatitude);
|
||||
$geoCodeUrl = $geoCodeUrlShort = '';
|
||||
$gLat = '55.6760968';
|
||||
$gLon = '12.5683371';
|
||||
|
||||
$lat = $row['latitude'] != '' ? htmlspecialchars($row['latitude']) : '';
|
||||
$lon = $row['longitude'] != '' ? htmlspecialchars($row['longitude']) : '';
|
||||
|
||||
if ($row['latitude'] || $row['longitude'] == '') {
|
||||
// remove all after first slash in address (top, floor ...)
|
||||
$address = preg_replace('/^([^\/]*).*$/', '$1', $row['address'] ?? '') . ' ';
|
||||
$address .= $row['city'] ?? '';
|
||||
// if we have at least some address part (saves geocoding calls)
|
||||
if ($address) {
|
||||
// base url
|
||||
$geoCodeUrlBase = 'https://nominatim.openstreetmap.org/search?q=';
|
||||
$geoCodeUrlAddress = $address;
|
||||
$geoCodeUrlCityOnly = ($row['city'] ?? '');
|
||||
// urlparams for nominatim which are fixed.
|
||||
$geoCodeUrlQuery = '&format=json&addressdetails=1&limit=1&polygon_svg=1';
|
||||
// replace newlines with spaces; remove multiple spaces
|
||||
$geoCodeUrl = trim(preg_replace('/\s\s+/', ' ', $geoCodeUrlBase . $geoCodeUrlAddress . $geoCodeUrlQuery));
|
||||
$geoCodeUrlShort = trim(preg_replace('/\s\s+/', ' ', $geoCodeUrlBase . $geoCodeUrlCityOnly . $geoCodeUrlQuery));
|
||||
}
|
||||
}
|
||||
|
||||
$resultArray['iconIdentifier'] = 'location-map-wizard';
|
||||
$resultArray['title'] = $this->getLanguageService()->sL('LLL:EXT:tt_address/Resources/Private/Language/locallang_db.xlf:tt_address.locationMapWizard');
|
||||
$resultArray['linkAttributes']['class'] = 'locationMapWizard ';
|
||||
$resultArray['linkAttributes']['data-label-title'] = $this->getLanguageService()->sL('LLL:EXT:tt_address/Resources/Private/Language/locallang_db.xlf:tt_address.locationMapWizard');
|
||||
$resultArray['linkAttributes']['data-label-close'] = $this->getLanguageService()->sL('LLL:EXT:tt_address/Resources/Private/Language/locallang_db.xlf:tt_address.locationMapWizard.close');
|
||||
$resultArray['linkAttributes']['data-label-import'] = $this->getLanguageService()->sL('LLL:EXT:tt_address/Resources/Private/Language/locallang_db.xlf:tt_address.locationMapWizard.import');
|
||||
$resultArray['linkAttributes']['data-lat'] = $lat;
|
||||
$resultArray['linkAttributes']['data-lon'] = $lon;
|
||||
$resultArray['linkAttributes']['data-glat'] = $gLat;
|
||||
$resultArray['linkAttributes']['data-glon'] = $gLon;
|
||||
$resultArray['linkAttributes']['data-geocodeurl'] = $geoCodeUrl;
|
||||
$resultArray['linkAttributes']['data-geocodeurlshort'] = $geoCodeUrlShort;
|
||||
$resultArray['linkAttributes']['data-namelat'] = htmlspecialchars($nameLatitude);
|
||||
$resultArray['linkAttributes']['data-namelon'] = htmlspecialchars($nameLongitude);
|
||||
$resultArray['linkAttributes']['data-namelat-active'] = htmlspecialchars($nameLatitudeActive);
|
||||
$resultArray['linkAttributes']['data-tiles'] = htmlspecialchars('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
|
||||
$resultArray['linkAttributes']['data-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';
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LanguageService
|
||||
*/
|
||||
protected function getLanguageService(): LanguageService
|
||||
{
|
||||
return $GLOBALS['LANG'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
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\BackendLayout\Grid\GridColumnItem;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Improve the rendering of the plugin in page module
|
||||
*/
|
||||
class TtAddressPreviewRenderer extends StandardContentPreviewRenderer
|
||||
{
|
||||
protected array $recordMapping = [
|
||||
'singleRecords' => [
|
||||
'table' => 'tt_address',
|
||||
'multiValue' => true,
|
||||
],
|
||||
'pages' => [
|
||||
'table' => 'pages',
|
||||
'multiValue' => true,
|
||||
],
|
||||
'singlePid' => [
|
||||
'table' => 'pages',
|
||||
'multiValue' => false,
|
||||
],
|
||||
'groups' => [
|
||||
'table' => 'sys_category',
|
||||
'multiValue' => true,
|
||||
],
|
||||
];
|
||||
|
||||
protected function renderContentElementPreviewFromFluidTemplate(array $row, ?GridColumnItem $item = null): ?string
|
||||
{
|
||||
$row = $this->enrichRow($row);
|
||||
return parent::renderContentElementPreviewFromFluidTemplate($row, $item);
|
||||
}
|
||||
|
||||
protected function enrichRow(array $row): array
|
||||
{
|
||||
$settings = $this->getFlexFormData($row['pi_flexform'] ?? '');
|
||||
|
||||
foreach ($this->recordMapping as $fieldName => $fieldConfiguration) {
|
||||
if ($settings['settings'][$fieldName] ?? false) {
|
||||
$records = $this->getRecords($fieldConfiguration['table'], $settings['settings'][$fieldName]);
|
||||
|
||||
if ($fieldConfiguration['multiValue']) {
|
||||
$row['_computed'][$fieldName] = $records;
|
||||
} else {
|
||||
$row['_computed'][$fieldName] = $records[0] ?: [];
|
||||
}
|
||||
}
|
||||
}
|
||||
$row['_computed']['lll'] = 'LLL:EXT:tt_address/Resources/Private/Language/ff/locallang_ff.xlf:pi1_flexform.';
|
||||
return $row;
|
||||
}
|
||||
|
||||
protected function getRecords(string $table, string $idList): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
|
||||
$queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
|
||||
|
||||
$rows = $queryBuilder
|
||||
->select('*')
|
||||
->from($table)
|
||||
->where(
|
||||
$queryBuilder->expr()->in(
|
||||
'uid',
|
||||
$queryBuilder->createNamedParameter(GeneralUtility::intExplode(',', $idList, true), Connection::PARAM_INT_ARRAY)
|
||||
)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
foreach ($rows as &$row) {
|
||||
$row['_computed']['title'] = BackendUtility::getRecordTitle($table, $row);
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
protected function getFlexFormData(string $flexforms): array
|
||||
{
|
||||
$settings = [];
|
||||
if (!empty($flexforms)) {
|
||||
$settings = GeneralUtility::makeInstance(FlexFormService::class)->convertFlexFormContentToArray($flexforms);
|
||||
}
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user