From 95fba4011af433ba75a05051802742d40d37c5cf Mon Sep 17 00:00:00 2001 From: Tac Tacelosky Date: Mon, 29 Apr 2024 07:59:15 -0600 Subject: [PATCH] Update README.md to working entity classes I also tweaked the $entity variable to $document to make it clearer, as $entity is generic --- README.md | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6b05867..b69d65d 100644 --- a/README.md +++ b/README.md @@ -109,17 +109,30 @@ This will lead you to something like the following, with some code skipped for b namespace App\Entity; +use App\Repository\DocumentRepository; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Webfactory\Bundle\PolyglotBundle\Attribute as Polyglot; +use Webfactory\Bundle\PolyglotBundle\Translatable; use Webfactory\Bundle\PolyglotBundle\TranslatableInterface; #[Polyglot\Locale(primary: "en_GB")] +#[ORM\Entity(repositoryClass: DocumentRepository::class)] class Document { + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column] + private ?int $id = null; + + public function getId(): ?int + { + return $this->id; + } + #[Polyglot\TranslationCollection] - #[ORM\OneToMany(targetEntity: \DocumentTranslation::class, mappedBy: 'entity')] + #[ORM\OneToMany(targetEntity: DocumentTranslation::class, mappedBy: 'document')] private Collection $translations; /** @@ -129,17 +142,18 @@ class Document #[ORM\Column(type: 'translatable_string')] private TranslatableInterface $text; - public function __construct(...) + public function __construct(string $text) { - // ... + $this->text = new Translatable($text, 'en_GB'); $this->translations = new ArrayCollection(); } - public function getText(): string + public function getText(): TranslatableInterface { - return $this->text->translate(); + return $this->text; } } + ``` ### Step 2) Create the Translation Entity @@ -158,14 +172,14 @@ Your code should look similar to this: