Skip to content

Commit bdf52eb

Browse files
committed
[BUGFIX] Respect class property types when creating Field objects from array#
This should fix a regression from 95b9b2c Related: #781
1 parent 295117b commit bdf52eb

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Classes/Hook/CreateMarker.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use TYPO3\CMS\Backend\Utility\BackendUtility as BackendUtilityCore;
1212
use TYPO3\CMS\Core\Utility\GeneralUtility;
1313
use TYPO3\CMS\Extbase\Object\Exception;
14+
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
1415

1516
/**
1617
* Class CreateMarker to autofill field marker with value from title e.g. {firstname}
@@ -207,7 +208,7 @@ protected function addExistingFields(): void
207208
{
208209
$fieldProperties = $this->getFieldProperties();
209210
foreach ($fieldProperties as $properties) {
210-
$this->addField($this->makeFieldFromProperties($properties));
211+
$this->addField($this->getFieldObjectFromProperties($properties));
211212
}
212213
}
213214

@@ -220,7 +221,7 @@ protected function addExistingFields(): void
220221
protected function addNewFields(): void
221222
{
222223
foreach ((array)($this->data[Field::TABLE_NAME] ?? []) as $fieldUid => $properties) {
223-
$this->addField($this->makeFieldFromProperties($properties, (string)$fieldUid));
224+
$this->addField($this->getFieldObjectFromProperties($properties, (string)$fieldUid));
224225
}
225226
}
226227

@@ -235,14 +236,12 @@ protected function addNewFields(): void
235236
* @param string $uid Number for persisted and string for new fields like "NEW5e2d7c8f48f4a868804329"
236237
* @return Field
237238
*/
238-
protected function makeFieldFromProperties(array $properties, string $uid = '0')
239+
protected function getFieldObjectFromProperties(array $properties, string $uid = '0'): Field
239240
{
240-
$field = GeneralUtility::makeInstance(Field::class);
241-
foreach ($properties as $key => $value) {
242-
$field->_setProperty(GeneralUtility::underscoredToLowerCamelCase($key), $value);
243-
}
241+
$dataMapper = GeneralUtility::makeInstance(DataMapper::class);
242+
$field = $dataMapper->map(Field::class, [$properties])[0];
244243
if (!empty($properties['sys_language_uid'])) {
245-
$field->_setProperty('_languageUid', $properties['sys_language_uid']);
244+
$field->_setProperty('_languageUid', (int)$properties['sys_language_uid']);
246245
}
247246
$field->setDescription((string)($properties['uid'] ?? '') > 0 ? (string)$properties['uid'] : $uid);
248247
return $field;

0 commit comments

Comments
 (0)