微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – Typo3:如何通过属性验证覆盖默认错误消息?

我有一个类Publisher,我想通过属性验证进行验证.
但我想覆盖认的错误消息.

以下是我的Publisher模型的代码段:

<?PHP
namespace Typo3\LpSurvey\Domain\Model;

use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;

class Publisher extends AbstractEntity
{

    /**
     * salutation
     *
     * @var bool
     * @validate NotEmpty
     */
    protected $salutation;

    ...
}

这是我对发布者对象的偏爱:

<div class="container publisher">
    <div class="row">
        <div class="col-sm-12">
            <legend>Anrede <em class="star">*</em></legend>
            // Error message output---------------------
            <f:render partial="FormErrorsPublisher" arguments="{field: 'newSigil.survey.publisher.salutation'}" />
            //------------------------------------------
            <label class="label-radio">
                <f:form.radio value="0" property="survey.publisher.salutation" />
                Frau
            </label>
            <label class="label-radio">
                <f:form.radio value="1" property="survey.publisher.salutation" />
                Herr
            </label>
        </div>
    </div>
    ...
</div>

这里我的FormErrorsPublisher部分(也是一个片段):

<f:form.validationResults for="{field}">
    <f:if condition="{validationResults.flattenedErrors}">
        <f:for each="{validationResults.flattenedErrors}" as="errors">
            <ul class="error-field">
                <f:for each="{errors}" as="error">
                    <li class="error">
                        {error}
                    </li>
                </f:for>
            </ul>
        </f:for>
    </f:if>
</f:form.validationResults>

现在,如果称呼字段为空,我会收到认的NotEmpty错误消息,但我想覆盖它.

也许在locallang.xlf中有错误代码

我试试这个,但没有解决方案:

<xliff version="1.0">
    <file source-language="en" datatype="plaintext" original="messages" date="2016-10-06T09:49:41Z" product-name="lp_survey">
        <header/>
        <body>
            ...
            <trans-unit id="survey.publisher.salutation.1221560910">
                <source>Der angegebene Wert ist leer.</source>
            </trans-unit>
        </body>
    </file>
</xliff>

有人有个主意吗?

解决方法:

我通常会这样定制它:

<f:form.validationResults for="{field}">
    <f:for each="{validationResults.flattenedErrors}" key="propertyPath" as="propertyErrors">
        <f:for each="{propertyErrors}" as="propertyError">
            <div class="form__field-error">
                <f:translate key="validator.{propertyPath}.{propertyError.code}" default="{propertyError}" />
            </div>
        </f:for>
    </f:for>
</f:form.validationResults>

然后locallang.xlf可以包含重写的验证错误消息(如果它下面是RegExp验证器的错误代码):

<trans-unit id="validator.object.property.1221565130">
    <source>Input doesn't match the regexp.</source>
</trans-unit>

上面的结构可以在没有参数的情况下使用,并且功能相同.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐