Extend TYPO3 femanager

你说的曾经没有我的故事 提交于 2019-12-06 02:30:21
Christian Ehret

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):

  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;
        }
     }
  1. 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');
  1. 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);
        }
    }
  1. 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

Christian Ehret

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!