我如何在 TYPO3 中使用 PHP 访问验证器中的临时参数(密码重新输入)而不创建额外的 sql 字段?

How can i access a temporarily argument (password-reenter) in a Validator with PHP in TYPO3 without make an extra sql-field?

TYPO3-版本:8.7.7

我想在 PHP 的 TYPO3 验证器中访问 $this->request->getArguments()

我在流体中设置了一个临时字段:

<label for="reenter_password" class="reenter_password{rm:hasError(property:'reenter_password',then:' text-danger')}">
    Reenter Password*
</label><br>
<f:form.password name="reenter_password" id="reenter_password"/>

如果我在 <f:form.password name="reenter_password" id="reenter_password"/> 中设置 property 而不是 name,我会得到以下错误:

#1297759968: Exception while property mapping at property path "": Property "reenter_password" was not found in target object of type "RM\RmRegistration\Domain\Model\User".

我不想设置模型-属性,因为这个 属性 应该只用于检查密码字段是否相等,不应该得到 TCA 或 SQL-Table 用于存储。

这是我的操作,我在这里调用验证器:

/**
 * Complete New User Registeration
 *
 * @param User $newRegisteredUser
 * @validate $newRegisteredUser \RM\RmRegistration\Validation\Validator\NewRegisteredUser
 * @validate $newRegisteredUser \RM\RmRegistration\Validation\Validator\CompleteProfileUser
 */
public function completeNewRegisteredUserAction(User $newRegisteredUser)
{
    // Store Changes, Update and Persist
    $newRegisteredUser->setPassword($this->saltThisPassword($newRegisteredUser->getPassword()));
    $this->userRepository->update($newRegisteredUser);
    $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager')->persistAll();
}

在验证程序中,我可以通过以下方式进入密码字段:

\TYPO3\CMS\Core\Utility\GeneralUtility::_POST()['tx_rmregistration_registration']['reenter_password']

但是是否可以像这样获取 UserModel 的临时值以在验证器中检查它:

// Compare Entered Passwords
if ($user->getPassword() == $user->getReenteredPassword()) {
    return TRUE;
} else {
    return FALSE;
}

为密码验证过程创建一个自己的(视图)模型,或者为 $newRegisteredUser 提供一个(临时的或非临时的)属性 作为重新输入的密码。然后使用自己的验证器 (see here).

class UserValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {

    /**
     * Object Manager
     *
     * @var \TYPO3\CMS\Extbase\Object\ObjectManager
     * @inject
     */
    protected $objectManager;

    /**
     * Is valid
     *
     * @param mixed $user
     * @return boolean
     */
    public function isValid($user) {
        if ($user->getPassword() !== $user->getPasswordConfirmation()) {
            $error = $this->objectManager->get(
                    'TYPO3\CMS\Extbase\Validation\Error',
                    'Password and password confirmation do not match.', time());
            $this->result->forProperty('passwordConfirmation')->addError($error);
            return FALSE;
        }
        return TRUE;
    }

}

并像这样在控制器中使用:

/**
 * action create
 *
 * @param \Vendor\Ext\Domain\Model\User $user
 * @validate $user \Vendor\Ext\Domain\Validator\UserValidator
 *
 * @return void
 */
public function createAction(\Vendor\Ext\Domain\Model\User $user) {

}