I am using TYPO3 10.4
with in2code/Femanager
extension to allow front end user registration and want to add a custom field to the form.
I have followed the docs about this here, and have my field in the form and I can save the field value if entered in the backend.
My problem is the field does not save the value when entered in the frontend form. I think I am missing something?
This is what I have:
/MyExtension/Configuration/Extbase/Persistence/Classes.php :
<?php
return [
\myVendor\MyExtension\Domain\Model\User::class => [
'tableName' => 'fe_users',
'recordType' => 0,
],
];
/MyExtension/Configuration/PageTS/PageTSConfig.tsconfig :
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\In2code\Femanager\Domain\Model\User::class] = [
'className' => \myVendor\MyExtension\Domain\Model\User::class,
];
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
->registerImplementation(
\In2code\Femanager\Domain\Model\User::class,
\myVendor\MyExtension\Domain\Model\User::class
);
/MyExtension/Classes/Domain/Model/User.php :
<?php
namespace myVendor\MyExtension\Domain\Model;
use TYPO3\CMS\Extbase\Domain\Model\Category;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
class User extends \In2code\Femanager\Domain\Model\User
{
protected string $myNewField;
public function getMyNewField(): string
{
return $this->myNewField;
}
public function setMyNewField(string $myNewField): void
{
$this->myNewField = $myNewField;
}
}
myExtension/ext_tables.sql :
CREATE TABLE fe_users (
myExtension_myNewField varchar(255) DEFAULT '' NOT NULL,
);
myExtension/Configuration/TCA/Overrides/fe_users.php :
<?php
defined('TYPO3_MODE') || die();
$GLOBALS['TCA']['fe_users']['ctrl']['type'] = 'tx_extbase_type';
$tmpFeUsersColumns = [
'myExtension_myNewField' => [
'exclude' => 1,
'label' => 'My New Field',
'config' => [
'type' => 'text',
],
]
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('fe_users', $tmpFeUsersColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('fe_users', 'myExtension_myNewField');
myExtension/Configuration/Extbase/Persistence/Classes.php :
<?php
declare(strict_types=1);
use myVendor\myExtension\Domain\Model\User;
return [
User::class => [
'tableName' => 'fe_users',
'recordType' => 0,
],
];
myExtension/ext_localconf.php :
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\In2code\Femanager\Domain\Model\User::class] = [
'className' => \myVendor\myExtension\Domain\Model\User::class,
];
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
->registerImplementation(
\In2code\Femanager\Domain\Model\User::class,
\myVendor\myExtension\Domain\Model\User::class
);
My problem was that the field name in ext_tables.sql
and fe_users.php
need to be named with underscores or all lowercase eg. my_new_field
.
And everywhere else uses camel case eg. myNewField
.
As mentioned in this answer here