src/Entity/LandingFooterItemTranslation.php line 29

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types;
  5. use Symfony\Component\Serializer\Annotation\Groups,
  6.     Symfony\Component\Validator\Constraints as Assert;
  7. use ApiPlatform\Metadata\ApiResource,
  8.     ApiPlatform\Metadata\ApiProperty,
  9.     ApiPlatform\Metadata\Get;
  10. use App\Entity\Trait\IdTrait,
  11.     App\Entity\Trait\UuidTrait,
  12.     App\Entity\Trait\TimestampableTrait,
  13.     App\Entity\Trait\TranslationTrait,
  14.     App\Entity\Interface\TranslationInterface,
  15.     App\Enum\Language;
  16. use App\Repository\LandingFooterItemTranslationRepository;
  17. #[ApiResource(
  18.     security'is_granted("' Landing::class . '")',
  19.     operations: [ new Get() ],
  20.     extraProperties: ['standard_put' => false],
  21. )]
  22. #[ORM\Entity(repositoryClassLandingFooterItemTranslationRepository::class)]
  23. class LandingFooterItemTranslation implements TranslationInterface
  24. {
  25.     use IdTrait,
  26.         UuidTrait,
  27.         TimestampableTrait,
  28.         TranslationTrait;
  29.     #[ApiProperty(description'Title')]
  30.     #[Groups(['read''write'])]
  31.     #[ORM\Column(typeTypes::STRINGlength511nullabletrue)]
  32.     private ?string $title null;
  33.     #[ApiProperty(description'Link')]
  34.     #[Groups(['read:' self::class, 'write'])]
  35.     #[ORM\Column(typeTypes::STRINGlength1023nullabletrue)]
  36.     private ?string $link null;
  37.     #[ApiProperty(description'Page'writableLinkfalse)]
  38.     #[Groups(['read:' self::class, 'write'])]
  39.     #[Assert\Expression(
  40.         expression'!value || value.getParent() === this.getParent().getParent()',
  41.         message'Cannot assign page from the outside of current landing.'
  42.     )]
  43.     #[ORM\ManyToOne(targetEntityLandingPage::class)]
  44.     #[ORM\JoinColumn(onDelete'set null')]
  45.     private ?LandingPage $page null;
  46.     public function __construct(LandingFooterItem $parentLanguage $lang)
  47.     {
  48.         $this->setUuid();
  49.         $this->parent $parent;
  50.         $this->lang $lang;
  51.         $this->createdAt = new \DateTimeImmutable();
  52.         $this->updatedAt = new \DateTimeImmutable();
  53.         $parent->addTranslation($this);
  54.     }
  55.     public function getTitle(): ?string
  56.     {
  57.         return $this->title;
  58.     }
  59.     public function setTitle(?string $title): self
  60.     {
  61.         $this->title $title;
  62.         return $this;
  63.     }
  64.     public function getLink(): ?string
  65.     {
  66.         return $this->link;
  67.     }
  68.     public function setLink(?string $link): self
  69.     {
  70.         if (empty($link)) {
  71.             $this->page null;
  72.         }
  73.         $this->link $link;
  74.         return $this;
  75.     }
  76.     public function getPage(): ?LandingPage
  77.     {
  78.         return $this->page;
  79.     }
  80.     public function setPage(?LandingPage $page): self
  81.     {
  82.         if ($page) {
  83.             $this->link null;
  84.         }
  85.         $this->page $page;
  86.         return $this;
  87.     }
  88.     public function getIsLinkable(): bool
  89.     {
  90.         return ! empty($this->link) || $this->page !== null;
  91.     }
  92. }