typo3extbasetypo3-extensionstypo3-10.x

Validation not working after overriding controller action


I want to add new action to EXT:femanager controller with new custom action.

I have override controller action with custom controller action and also flexform controller action.

ext_localconf.php

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'][] = \Vandor\Ext\Hooks\OverwriteFlexForm::class . '->overwrite';

OverwriteFlexForm

<T3DataStructure>
    <meta>
        <langDisable>1</langDisable>
    </meta>
    <sheets>
        <main>
            <ROOT>
                <TCEforms>
                    <sheetTitle>LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:flexform.main.title</sheetTitle>
                </TCEforms>
                <type>array</type>
                <el>
                    <!-- Also set allowed controller actions in \In2code\Femanager\Domain\Repository\PluginRepository::$scaString -->
                    <switchableControllerActions>
                        <TCEforms>
                            <label>LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:flexform.main.view</label>
                            <onChange>reload</onChange>
                            <config>
                                <type>select</type>
                                <renderType>selectSingle</renderType>
                                <items type="array">
                                    <numIndex index="0" type="array">
                                        <numIndex index="0">LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:pleaseChoose</numIndex>
                                        <numIndex index="1"></numIndex>
                                    </numIndex>
                                    <numIndex index="1" type="array">
                                        <numIndex index="0">LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:flexform.main.view.0</numIndex>
                                        <numIndex index="1">New->new;New->create;New->createStatus;New->confirmCreateRequest;</numIndex>
                                    </numIndex>
                                    <numIndex index="2" type="array">
                                        <numIndex index="0">LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:flexform.main.view.1</numIndex>
                                        <numIndex index="1">Edit->edit;Edit->update;Edit->delete;Edit->confirmUpdateRequest;User->imageDelete;User->fileDelete;</numIndex>
                                    </numIndex>
                                    <numIndex index="3" type="array">
                                        <numIndex index="0">LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:flexform.main.view.2</numIndex>
                                        <numIndex index="1">User->list;User->show;</numIndex>
                                    </numIndex>
                                    <numIndex index="4" type="array">
                                        <numIndex index="0">LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:flexform.main.view.3</numIndex>
                                        <numIndex index="1">User->show;</numIndex>
                                    </numIndex>
                                    <numIndex index="5" type="array">
                                        <numIndex index="0">LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:flexform.main.view.4</numIndex>
                                        <numIndex index="1">Invitation->new;Invitation->create;Invitation->edit;Invitation->update;Invitation->delete;Invitation->status;</numIndex>
                                    </numIndex>
                                    <numIndex index="6" type="array">
                                        <numIndex index="0">LLL:EXT:femanager/Resources/Private/Language/locallang_db.xlf:flexform.main.view.5</numIndex>
                                        <numIndex index="1">New->resendConfirmationDialogue;New->resendConfirmationMail;New->confirmCreateRequest;</numIndex>
                                    </numIndex>
                                </items>
                                <maxitems>1</maxitems>
                                <size>1</size>
                            </config>
                        </TCEforms>
                    </switchableControllerActions>
                </el>
            </ROOT>
        </main>
</sheets>
</T3DataStructure>

Here, User->fileDelete is the new action I added.

<?php
declare(strict_types = 1);
namespace Vandor\Ext\Controller;

use In2code\Femanager\Domain\Model\Log;
use In2code\Femanager\Domain\Model\User;
use In2code\Femanager\Domain\Validator\ClientsideValidator;
use In2code\Femanager\Event\ImpersonateEvent;
use In2code\Femanager\Utility\BackendUserUtility;
use In2code\Femanager\Utility\FrontendUtility;
use In2code\Femanager\Utility\LocalizationUtility;
use In2code\Femanager\Utility\UserUtility;
use TYPO3\CMS\Core\Error\Http\UnauthorizedException;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

/**
 * Class UserController
 */
class UserController extends \In2code\Femanager\Controller\UserController
{
    /**
     * @param User $user
     * @throws \Exception
     */
    public function fileDeleteAction(User $user)
    {
        if (UserUtility::getCurrentUser() !== $user) {
            throw new UnauthorizedException('You are not allowed to delete this image', 1516373759972);
        }
        $user->setCompanyDocuments($this->objectManager->get(ObjectStorage::class));
        $this->userRepository->update($user);
        $this->logUtility->log(Log::STATUS_PROFILEUPDATEIMAGEDELETE, $user);
        $this->addFlashMessage(LocalizationUtility::translateByState(Log::STATUS_PROFILEUPDATEIMAGEDELETE));
        $this->redirectToUri(FrontendUtility::getUriToCurrentPage());
    }
}

Here, validation failed always on edit form.Showing error "Das Feld konnte nicht validiert werden.". Any suggestion?


Solution

  • I found the solution, take look below:

    We have to include custom action here. For that, we need to extend PluginRepository.php to our own extension. Follow the steps below:

    ext_localconf.php

    $container = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(TYPO3\CMS\Extbase\Object\Container\Container::class);
    $container->registerImplementation(
        PluginRepository::class,
        customPluginRepository::class
    );
    

    and create new repository, customPluginRepository.php

    <?php
    declare(strict_types = 1);
    namespace Vandor\Ext\Domain\Repository;
    
    use In2code\Femanager\Domain\Repository\PluginRepository;
    
    /**
     * Class PluginRepository
     */
    class customPluginRepository extends PluginRepository
    {
        /**
         * @var array
         */
        protected $scaString = [
            'new' => 'New->new;New->create;New->createStatus;New->confirmCreateRequest;',
            'edit' => 'Edit->edit;Edit->update;Edit->delete;Edit->confirmUpdateRequest;User->imageDelete;User->fileDelete;',
            'invitation' => 'Invitation->new;Invitation->create;Invitation->edit;'
                . 'Invitation->update;Invitation->delete;Invitation->status;',
        ];
    }
    

    Here User->fileDelete is the custom action extended to delete file (For custom upload field) and this way, issue will be resolve.

    Here is ticket: https://github.com/in2code-de/femanager/issues/484