Commit 560ed4aa authored by Jonas Götze's avatar Jonas Götze
Browse files

[WIP][FEATURE] field- and form-configuration to add a new location and attach it to the new event

todo: improve UI (modal?)
future todo: hide the fields, provide new Locations via Maps API in the suggest and fill the fields via JS with the data provided by the API
parent c18e21d0
Pipeline #13372 failed with stages
in 1 minute and 42 seconds
...@@ -18,6 +18,7 @@ namespace T3o\T3orgLayout\Domain\Finishers; ...@@ -18,6 +18,7 @@ namespace T3o\T3orgLayout\Domain\Finishers;
use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\DataHandling\SlugHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException; use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
...@@ -87,8 +88,8 @@ class T3oSaveToDatabaseFinisher extends \TYPO3\CMS\Form\Domain\Finishers\SaveToD ...@@ -87,8 +88,8 @@ class T3oSaveToDatabaseFinisher extends \TYPO3\CMS\Form\Domain\Finishers\SaveToD
$slugFieldName = $this->parseOption('slugFieldName'); $slugFieldName = $this->parseOption('slugFieldName');
if ($slugFieldName !== null && $this->options['mode'] === 'insert') { if ($slugFieldName !== null && $this->options['mode'] === 'insert') {
$fieldConfig = $GLOBALS['TCA'][$this->options['table']]['columns'][$slugFieldName]['config']; $fieldConfig = $GLOBALS['TCA'][$this->options['table']]['columns'][$slugFieldName]['config'];
$slugHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( $slugHelper = GeneralUtility::makeInstance(
\TYPO3\CMS\Core\DataHandling\SlugHelper::class, SlugHelper::class,
$this->options['table'], $this->options['table'],
$slugFieldName, $slugFieldName,
$fieldConfig $fieldConfig
...@@ -115,8 +116,16 @@ class T3oSaveToDatabaseFinisher extends \TYPO3\CMS\Form\Domain\Finishers\SaveToD ...@@ -115,8 +116,16 @@ class T3oSaveToDatabaseFinisher extends \TYPO3\CMS\Form\Domain\Finishers\SaveToD
* @param array $databaseData * @param array $databaseData
* @return array * @return array
*/ */
protected function prepareData(array $elementsConfiguration, array $databaseData) protected function prepareData(array $elementsConfiguration, array $databaseData): array
{ {
if (isset($this->options['requiredFields'])) {
$formValues = $this->getFormValues();
foreach ($this->options['requiredFields'] as $requiredFieldIdentifier) {
if (!isset($formValues[$requiredFieldIdentifier]) || empty($formValues[$requiredFieldIdentifier])) {
return [];
}
}
}
$databaseData = parent::prepareData($elementsConfiguration, $databaseData); $databaseData = parent::prepareData($elementsConfiguration, $databaseData);
foreach ($this->getFormValues() as $elementIdentifier => $elementValue) { foreach ($this->getFormValues() as $elementIdentifier => $elementValue) {
if ($elementValue instanceof \DateTime) { if ($elementValue instanceof \DateTime) {
...@@ -135,4 +144,27 @@ class T3oSaveToDatabaseFinisher extends \TYPO3\CMS\Form\Domain\Finishers\SaveToD ...@@ -135,4 +144,27 @@ class T3oSaveToDatabaseFinisher extends \TYPO3\CMS\Form\Domain\Finishers\SaveToD
} }
return $databaseData; return $databaseData;
} }
/**
* Save or insert the values from
* $databaseData into the table $table
*
* @param array $databaseData
* @param string $table
* @param int $iterationCount
*/
protected function saveToDatabase(array $databaseData, string $table, int $iterationCount): void
{
if (empty($databaseData)) {
if (isset($this->options['defaultInsertedUidIfEmpty'])) {
$this->finisherContext->getFinisherVariableProvider()->add(
$this->shortFinisherIdentifier,
'insertedUids.' . $iterationCount,
(int) $this->options['defaultInsertedUidIfEmpty']
);
}
} else {
parent::saveToDatabase($databaseData, $table, $iterationCount);
}
}
} }
...@@ -9,6 +9,35 @@ finishers: ...@@ -9,6 +9,35 @@ finishers:
- -
identifier: T3oSaveToDatabase identifier: T3oSaveToDatabase
options: options:
-
table: tx_sfeventmgt_domain_model_location
mode: insert
slugFieldName: 'slug'
requiredFields:
- newLocationTitle
defaultInsertedUidIfEmpty: 0
elements:
newLocationTitle:
mapOnDatabaseColumn: 'title'
newLocationAddress:
mapOnDatabaseColumn: 'address'
newLocationZip:
mapOnDatabaseColumn: 'zip'
newLocationCity:
mapOnDatabaseColumn: 'city'
newLocationCountry:
mapOnDatabaseColumn: 'country'
newLocationLink:
mapOnDatabaseColumn: 'link'
newLocationLatitude:
mapOnDatabaseColumn: 'latitude'
newLocationLongitude:
mapOnDatabaseColumn: 'longitude'
newLocationDescription:
mapOnDatabaseColumn: 'description'
databaseColumnMappings:
pid:
value: 180
- -
table: 'tx_sfeventmgt_domain_model_event' table: 'tx_sfeventmgt_domain_model_event'
mode: insert mode: insert
...@@ -27,6 +56,9 @@ finishers: ...@@ -27,6 +56,9 @@ finishers:
value: '{__currentTimestamp}' value: '{__currentTimestamp}'
tstamp: tstamp:
value: '{__currentTimestamp}' value: '{__currentTimestamp}'
location:
value: '{T3oSaveToDatabase.insertedUids.0}'
skipIfValueIsEmpty: true
elements: elements:
fileupload: fileupload:
mapOnDatabaseColumn: 'image' mapOnDatabaseColumn: 'image'
...@@ -52,6 +84,7 @@ finishers: ...@@ -52,6 +84,7 @@ finishers:
mapOnDatabaseColumn: 'description' mapOnDatabaseColumn: 'description'
location: location:
mapOnDatabaseColumn: 'location' mapOnDatabaseColumn: 'location'
skipIfValueIsEmpty: true
link: link:
mapOnDatabaseColumn: 'link' mapOnDatabaseColumn: 'link'
program: program:
...@@ -77,12 +110,12 @@ finishers: ...@@ -77,12 +110,12 @@ finishers:
crdate: crdate:
value: '{__currentTimestamp}' value: '{__currentTimestamp}'
uid_foreign: uid_foreign:
value: '{T3oSaveToDatabase.insertedUids.0}' value: '{T3oSaveToDatabase.insertedUids.1}'
- -
table: 'sys_file_reference' table: 'sys_file_reference'
mode: update mode: update
whereClause: whereClause:
uid_foreign: '{T3oSaveToDatabase.insertedUids.0}' uid_foreign: '{T3oSaveToDatabase.insertedUids.1}'
uid_local: 0 uid_local: 0
databaseColumnMappings: databaseColumnMappings:
pid: pid:
...@@ -101,8 +134,7 @@ finishers: ...@@ -101,8 +134,7 @@ finishers:
fieldname: fieldname:
value: 'category' value: 'category'
uid_foreign: uid_foreign:
value: '{T3oSaveToDatabase.insertedUids.0}' value: '{T3oSaveToDatabase.insertedUids.1}'
- -
options: options:
subject: 'new Event submitted on typo3.org' subject: 'new Event submitted on typo3.org'
...@@ -237,6 +269,102 @@ renderables: ...@@ -237,6 +269,102 @@ renderables:
elementClassAttribute: 'js__eventsubmissionform__location-search_input' elementClassAttribute: 'js__eventsubmissionform__location-search_input'
fluidAdditionalAttributes: fluidAdditionalAttributes:
data-location-search-target: 'location' data-location-search-target: 'location'
- type: Fieldset
identifier: fieldset-event-new-location
label: 'OR add new location'
properties:
elementClassAttribute: 'ml-4 pl-4 border-left'
renderables:
-
defaultValue: ''
type: Text
identifier: newLocationTitle
label: Location title
properties:
elementDescription: ''
-
defaultValue: ''
type: Textarea
identifier: newLocationAddress
label: Location Address
properties:
elementDescription: ''
-
type: GridRow
identifier: gridrow-event-newlocation-1
label: 'Grid: Row'
renderables:
-
defaultValue: ''
type: Text
identifier: newLocationZip
label: Location zip
properties:
elementDescription: ''
-
defaultValue: ''
type: Text
identifier: newLocationCity
label: Location city
properties:
elementDescription: ''
-
type: GridRow
identifier: gridrow-event-newlocation-2
label: 'Grid: Row'
renderables:
-
defaultValue: ''
type: Text
identifier: newLocationCountry
label: Location country
properties:
elementDescription: ''
-
defaultValue: ''
type: Url
identifier: newLocationLink
label: Location link
properties:
elementDescription: ''
-
type: GridRow
identifier: gridrow-event-newlocation-3
label: 'Grid: Row'
renderables:
-
defaultValue: ''
type: Text
identifier: newLocationLatitude
label: Location latitude
validators:
-
identifier: NumberRange
options:
minimum: -90
maximum: 90
properties:
elementDescription: ''
-
defaultValue: ''
type: Text
identifier: newLocationLongitude
label: Location longitude
validators:
-
identifier: NumberRange
options:
minimum: -180
maximum: 180
properties:
elementDescription: ''
-
defaultValue: ''
type: Textarea
identifier: newLocationDescription
label: Location description
properties:
elementDescription: ''
- -
defaultValue: '' defaultValue: ''
type: Url type: Url
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
list-style-type: none; list-style-type: none;
margin: 0; margin: 0;
padding: 0; padding: 0;
z-index: 1;
} }
.js__eventsubmissionform__location-search_resultlist li { .js__eventsubmissionform__location-search_resultlist li {
width: 100%; width: 100%;
......
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