Felix Felix - 4 months ago 25
PHP Question

Typo3: How can I overwrite the default error message by property validation?

I have a class

, which I want to validate with property validation.
But I want to overwrite the default error messages.

Here is a snippet from my

namespace Typo3\LpSurvey\Domain\Model;

use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;

class Publisher extends AbstractEntity

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


Here is my partial for my publisher object:

<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" />
<label class="label-radio">
<f:form.radio value="1" property="survey.publisher.salutation" />

And here my
partial (also a snippet):

<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">

Now if the salutation field is empty I get the default
error message, but I want to overwrite this.

Maybe in the locallang.xlf with the error code?

I try this, but no solution:

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

Have anyone an idea?


I'm usually customizing it like this:

<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}" />

And then locallang.xlf can contain overridden validation error messages (in case below it is an error code of RegExp validator):

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

The construction above can be used without for argument and will function the same.