Does anyone have a working example how to extend femanager 3.3.0 on TYPO3 8.7?
I created a new Extension which does all the stuff (new database fields for fe_user, TCA, Partials,....). I have the new fields in the femanager plugin and can select them for the frontend.
Registering IS WORKING: the new fields are saved in the database.
There is a Warning in the Log:
Core: Error handler (FE):
PHP Warning: Declaration of TOCO3\TocoLedes\Controller\NewController::createAction(TOCO3\TocoLedes\Domain\Model\User $user)
should be compatible with In2code\Femanager\Controller\NewController::createAction(In2code\Femanager\Domain\Model\User $user) in \www\typo3conf\ext\toco_ledes\Classes\Controller\NewController.php line 0
Nevertheless this seems not be a problem.
BUT: Editing
The Profile Edit Page shows all my new fields (as selected in the Plugin) but does NOT load the values of these fields (they are empty). If I try to save the profile I get the following error:
Core: Exception handler (WEB):
Uncaught TYPO3 Exception: #1297759968:
Exception while property mapping at property path "":
Property "newfield" was not found in target object of type
"In2code\Femanager\Domain\Model\User". |
TYPO3\CMS\Extbase\Property\Exception thrown in file
\www\typo3_src-8.7.8\typo3\sysext\extbase\Classes\Property\PropertyMapper.php in line 127.
It is very strange that the creating (register) is working, but the editing does not!
I think the interessing parts are
config.tx_extbase{
persistence{
classes{
In2code\Femanager\Domain\Model\User {
subclasses {
0 = TOCO3\TocoLedes\Domain\Model\User
}
}
TOCO3\TocoLedes\Domain\Model\User {
mapping {
tableName = fe_users
recordType = 0
}
}
}
}
objects {
In2code\Femanager\Controller\NewController.className = TOCO3\TocoLedes\Controller\NewController
In2code\Femanager\Controller\EditController.className = TOCO3\TocoLedes\Controller\EditController
}
}
EditController.php
namespace TOCO3\TocoLedes\Controller;
class EditController extends \In2code\Femanager\Controller\EditController {
/**
* action update
*
* @param TOCO3\TocoLedes\Domain\Model\User $user
* @validate $user In2code\Femanager\Domain\Validator\ServersideValidator
* @validate $user In2code\Femanager\Domain\Validator\PasswordValidator
* @return void
*/
public function updateAction(\TOCO3\TocoLedes\Domain\Model\User $user) {
parent::updateAction($user);
}
}
I'm looking forward any ideas or - this would be great - a working sample extension (Unfortunately femanagerextended ist outdated :-( )
To help others having the same problem perhaps I have a solution for the PHP 7 warnings too (with help of Steffen Kamper and some hints from here: https://github.com/einpraegsam/femanagerextended/issues/1):
Create an XCLASS
myext/XClass/Extbase/Mvc/Controller/Argument.php
<?php
namespace TOCO3\MyExt\Xclass\Extbase\Mvc\Controller;
class Argument extends \TYPO3\CMS\Extbase\Mvc\Controller\Argument
{
/**
* Set data type for femanager workaround.
* Workaround to avoid php7 warnings of wrong type hint.
*
* @param $dataType
* @return $this
*/
public function setDataType($dataType) {
$this->dataType = $dataType;
return $this;
}
}
- Register this XClass
myext/ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument'] = array('className' => 'TOCO3\\MyExt\\Xclass\\Extbase\\Mvc\\Controller\\Argument');
- In NewController.php
<?php
namespace TOCO3\MyExt\Controller;
use TOCO3\MYExt\Domain\Model\User;
class NewController extends \In2code\Femanager\Controller\NewController {
/**
* @return void
*/
public function initializeCreateAction()
{
if ($this->arguments->hasArgument('user')) {
// Workaround to avoid php7 warnings of wrong type hint.
/** @var \TOCO3\MyExt\Xclass\Extbase\Mvc\Controller\Argument $user */
$user = $this->arguments['user'];
$user->setDataType(\TOCO3\MyExt\Domain\Model\User::class);
}
}
/**
* action create
*
* @param User $user
* @validate $user In2code\Femanager\Domain\Validator\ServersideValidator
* @validate $user In2code\Femanager\Domain\Validator\PasswordValidator
* @validate $user In2code\Femanager\Domain\Validator\CaptchaValidator
* @return void
*/
public function createAction(\In2code\Femanager\Domain\Model\User $user) {
parent::createAction($user);
}
}
- In EditController.php
<?php
namespace TOCO3\MyExt\Controller;
use \TOCO3\MyExt\Domain\Model\User;
class EditController extends \In2code\Femanager\Controller\EditController {
/**
* @return void
*/
public function initializeUpdateAction()
{
if ($this->arguments->hasArgument('user')) {
// Workaround to avoid php7 warnings of wrong type hint.
/** @var \TOCO3\MyExt\Xclass\Extbase\Mvc\Controller\Argument $user */
$user = $this->arguments['user'];
$user->setDataType(\TOCO3\MyExt\Domain\Model\User::class);
}
}
/**
* action update
*
* @param User $user
* @validate $user In2code\Femanager\Domain\Validator\ServersideValidator
* @validate $user In2code\Femanager\Domain\Validator\PasswordValidator
* @validate $user In2code\Femanager\Domain\Validator\CaptchaValidator
* @return void
*/
public function updateAction(\In2code\Femanager\Domain\Model\User $user) {
parent::updateAction($user);
}
}
Just use the example on github
https://github.com/einpraegsam/femanagerextended
It works perfectly with femananger 3.3.0
The problem is that the following TypoScript was not included properly via Extension include. If I add it directly as extension template at the profile editing page it works!?
config.tx_extbase{
persistence{
classes{
In2code\Femanager\Domain\Model\User {
subclasses {
0 = TOCO3\TocoLedes\Domain\Model\User
}
}
TOCO3\TocoLedes\Domain\Model\User {
mapping {
tableName = fe_users
recordType = 0
}
}
}
}
objects {
In2code\Femanager\Controller\NewController.className = TOCO3\TocoLedes\Controller\NewController
In2code\Femanager\Controller\EditController.className = TOCO3\TocoLedes\Controller\EditController
}
}
I'll have to investigate it some time to find the reason for that ;-)
More Information, see
How to extend femanager controller under php 7
Look also my comments .. I had no problems with the outdated extension femanagerextended
https://github.com/einpraegsam/femanagerextended
Good luck.