Since using PHP 7.0 and higher, the strict mode of php generates warnings like this:
PHP Warning: Declaration of In2code\Femanagerextended\Controller\EditController::updateAction(In2code\Femanagerextended\Domain\Model\User $user) should be compatible with In2code\Femanager\Controller\EditController::updateAction(In2code\Femanager\Domain\Model\User $user) in ($PATH)\typo3conf\ext\femanagerextended\Classes\Controller\EditController.php line 17
when trying to extend an existing controller of the TYPO3 Extension femanager using the described way in the best practice section of the manual:
<?php
namespace In2code\Femanagerextended\Controller;
use In2code\Femanager\Controller\EditController as EditControllerFemanager;
use In2code\Femanagerextended\Domain\Model\User;
/**
* Class EditController
*
* @package In2code\Femanagerextended\Controller
*/
class EditController extends EditControllerFemanager
{
/**
* action update
*
* @param User $user
* @validate $user In2code\Femanager\Domain\Validator\ServersideValidator
* @validate $user In2code\Femanager\Domain\Validator\PasswordValidator
* @return void
*/
public function updateAction(User $user)
{
parent::updateAction($user);
}
}
A possible solution, worked out by Wolfgang Klinger, is to XClass the \TYPO3\CMS\Extbase\Mvc\Controller\Argument class.
This class has a protected property "dataType", which usually has no setter.
Using the XClass mechanism of TYPO3 it is possible to add a setDataType method to enable the manual overriding of this property.
Armed with this, it's now possible to overwrite the usually automatic detected data type inside the (magic) initialize actions of the extending edit/invitation/new-controller.
The important thing is, not to change the type hints and annotations of the "normal" Actions (newAction, createAction ...), but add something like this to the corresponding initialize actions:
public function initializeNewAction()
{
if ($this->arguments->hasArgument('user')) {
// Workaround to avoid php7 warnings of wrong type hint.
/** @var \Mediagear\Jdcompetition\Xclass\Extbase\Mvc\Controller\Argument $user */
$user = $this->arguments['user'];
$user->setDataType(\Vendor\Extension\Domain\Model\User::class);
}
}