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>
上面的结构可以在没有参数的情况下使用,并且功能相同.
标签:php,validation,typo3,typo3-7-6-x,extbase 来源: https://codeday.me/bug/20190717/1487555.html