1111use TYPO3 \CMS \Backend \Utility \BackendUtility as BackendUtilityCore ;
1212use TYPO3 \CMS \Core \Utility \GeneralUtility ;
1313use 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,15 @@ 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 ) ;
241+ $ dataMapper = GeneralUtility::makeInstance (DataMapper ::class);
242+ if ( isset ( $ properties[ ' uid ' ]) === false ) {
243+ $ properties [ ' uid ' ] = null ;
243244 }
245+ $ field = $ dataMapper ->map (Field::class, [$ properties ])[0 ];
244246 if (!empty ($ properties ['sys_language_uid ' ])) {
245- $ field ->_setProperty ('_languageUid ' , $ properties ['sys_language_uid ' ]);
247+ $ field ->_setProperty ('_languageUid ' , ( int ) $ properties ['sys_language_uid ' ]);
246248 }
247249 $ field ->setDescription ((string )($ properties ['uid ' ] ?? '' ) > 0 ? (string )$ properties ['uid ' ] : $ uid );
248250 return $ field ;
0 commit comments