a2lix / TranslationFormBundle

Ease translations with some dedicated Symfony form types
https://a2lix.fr/bundles/translation-form
MIT License
330 stars 138 forks source link

Required languages not validated #361

Closed ldecoker closed 2 years ago

ldecoker commented 2 years ago

Hello!

I am using a2lix translation form (3.0.7) with doctrine behavior (2.2.0). I managed to get the translated entities validated (using validation in yaml file) but this only works when at least one field in each language is populated. If for example you have 2 required languages and you add informations for one and leave all fields for second mandatory language empty, this will not generate a validation error. Any idea on how to fix that? Thx!

jerome-fix commented 2 years ago

HI, I have the same issue. I found a workaround by redefining the TranslationMethodsTrait::isEmpty method from KnpLabs/DoctrineBehaviors


trait FixValidationTranslationTrait
{
    public function isEmpty(): bool
    {
        return false;
    }
}

And in my translation class


use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslationTrait;

class ServiceTranslation implements TranslationInterface
{
    use FixValidationTranslationTrait {
        FixValidationTranslationTrait::isEmpty insteadof TranslationTrait;
    }

    use TranslationTrait;

[...]
}

In my particular case it works ;-)

Jérôme

ldecoker commented 2 years ago

Hello @jerome-fix !

Thx for this! I apply it and indeed it works but only when creating new object. When I edit it and remove the content of one mandatory field, it crashed. Was it the same for you?

What is supposed to do the isEmpty function?

thx!