Commit 0637bb51 authored by Stefan Busemann's avatar Stefan Busemann
Browse files

Merge branch '290-add-hook-for-events-to-get-lat-and-lng-data-when-saving-location' into 'develop'

Resolve "Add hook for events to get lat and lng data when saving location"

Closes #290

See merge request t3o/typo3.org!213
parents 4136479d 73a4fb08
Pipeline #5216 passed with stages
in 4 minutes and 36 seconds
<?php
namespace T3o\T3orgLayout\Hook;
/*
* This file is part of a TYPO3 extension.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
class DataHandlerHook
{
protected $eventLocationTableName = 'tx_sfeventmgt_domain_model_location';
public function processDatamap_afterDatabaseOperations(
$status,
$table,
$id,
array &$fieldArray,
\TYPO3\CMS\Core\DataHandling\DataHandler $pObj
) {
if ($table === $this->eventLocationTableName) {
$locationChanged = false;
$fieldsToWatch = [
'address',
'zip',
'city',
'country'
];
foreach ($fieldsToWatch as $toWatch) {
if (isset($fieldArray[$toWatch])) {
$locationChanged = true;
}
}
if ($locationChanged) {
$record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($table, $id);
$address = implode(
' ',
[
str_replace(PHP_EOL, ' ', $record['address']),
$record['zip'],
$record['city'],
$record['country'],
]
);
$url = 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' . urlencode($address);
$result = json_decode(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($url), true);
$locationData = $result['results'][0]['geometry']['location'];
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
->getConnectionForTable($this->eventLocationTableName)
->update(
$this->eventLocationTableName,
[
'latitude' => $locationData['lat'],
'longitude' => $locationData['lng']
],
['uid' => $id]
);
}
}
}
}
...@@ -12,3 +12,5 @@ ...@@ -12,3 +12,5 @@
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['SolrSuggest'] = \T3o\T3orgLayout\Controller\SolrInstantSearchController::class . '::suggest'; $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['SolrSuggest'] = \T3o\T3orgLayout\Controller\SolrInstantSearchController::class . '::suggest';
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['Domain/Model/News'][] = 't3org_layout'; $GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['Domain/Model/News'][] = 't3org_layout';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['t3org_layout'] = \T3o\T3orgLayout\Hook\DataHandlerHook::class;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment