Problème de traduction d'entité avec Symfony 7

Par maioun, il y a 2 ans


Si après avoir suivi le tutoriel Symfony 7 au chapitre Internationalisation et avoir fait un :

php bin/console make:migration

vous avez :

In AnnotationException.php line 36: [Semantical Error] The class "Doctrine\ORM\Mapping\MappedSuperclass" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "Doctrine\ORM\Mapping\MappedSuperclass". If it is indeed no annotation, then you need to add @IgnoreAnnotation("ORM\MappedSuperclass") to the _class_ doc comment of class Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation. make:migration [--formatted] [--configuration [CONFIGURATION]]

Voici la solution

  1. Enlever les modifications faites aux fichiers (pour la traduction du champ title de l'entité Recipe) :

    • doctrine.yaml
    • Recipe.php
  2. Désinstaller stof/doctrine-extensions-bundle

    composer remove stof/doctrine-extensions-bundle
  3. Supprimer le cache de Symfony

    php bin/console cache:clear

    4 . Réinstaller stof/doctrine-extensions-bundle

    composer require stof/doctrine-extensions-bundle
  4. Supprimer le cache de Symfony (pas nécessaire, mais pour être sûr ;-p)

    php bin/console cache:clear
  5. Refaire les modifications des fichiers :

    • doctrine.yaml doctrine: dbal: ... orm: ... mappings: App: ... gedmo_translatable: type: attribute prefix: Gedmo\Translatable\Entity dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity" alias: GedmoTranslatable # (optional) it will default to the name set for the mapping is_bundle: false ...
    • Recipe.php <?php namespace App\Entity; ... use Gedmo\Mapping\Annotation\Translatable; ... class Recipe { ... #[Translatable] private string $title = ''; ... }

Maintenant, lorsque vous faites un :

php bin/console make:migration

Success!

2 réponses

maioun, il y a 2 ans

Je me suis apperçu qu'en remodifiant stof_doctrine_extensions

stof_doctrine_extensions: default_locale: fr orm: default: translatable: true

j'ai l'erreur qui revenait, mais dans la page du navigateur cette fois 😭

Après plusiseurs de réflexion sans pouvoir comprendre d'où venait le problème, une idée met venu à l'esprit.
Et si...

Eurêka
C'est encore un problème de compatibilité non résolu de gedmo/doctrine-extensions avec doctrine/orm dans la version "^3.1".
Il faut le downgrader en modifiant le composer.json :

{ ... "require": { "doctrine/orm": "^2.18.0", }, ... }

Ensuite, il ne reste plus qu'à

composer update

Enfin ça fonctionne !!!

Toleyah, il y a 1 an

Bonjour,

je rencontre le même soucis de compatibilité.

J'ai tenté ta première méthode mais en modifiant le stof_doctrine_extensions.yml ... cata ...
Je ne peux pas downgrade doctrine/orm car j'ai des soucis de compatibilité ailleurs.

Je suis en Php 8.3, symfony 6.4.
J'ai monté doctrine/orm en 3.* pour être compatible avec des bundle interne et ... Gedmo ne suis pas !
J'ai désinstallé stof puis réinstallé, aucun changement.

J'utilise blameable/softdeleteable/timestampable et loggable de stof.

please ... help :)