src/Entity/DomainTranslation.php line 27
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\Get;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslationTrait,
App\Entity\Interface\TranslationInterface,
App\Enum\Language,
App\Repository\DomainTranslationRepository;
#[ApiResource(
security: 'is_granted("' . Domain::class . '")',
operations: [ new Get() ],
extraProperties: ['standard_put' => false],
)]
#[ORM\Entity(repositoryClass: DomainTranslationRepository::class)]
class DomainTranslation implements TranslationInterface
{
use IdTrait,
UuidTrait,
TimestampableTrait,
TranslationTrait;
#[ApiProperty(description: 'Title')]
#[Groups(['read', 'write'])]
#[ORM\Column(type: Types::STRING, length: 1023, nullable: true)]
private ?string $title = null;
public function __construct(Domain $parent, Language $lang)
{
$this->setUuid();
$this->parent = $parent;
$this->lang = $lang;
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent->addTranslation($this);
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
#[Groups(['read'])]
public function getFullDomainTitle(): ?string
{
return $this->getParentDomainTitle($this->getParent(), $this->lang) . $this->title;
}
private function getParentDomainTitle(Domain $domain, Language $lang): ?string
{
if (! $domain->getParent()) {
return null;
}
/** @var DomainTranslation */
$langTranslation = $domain->getTranslations()[$lang->value];
return $this->getParentDomainTitle($domain->getParent(), $lang)
. $langTranslation->getTitle()
. ' - ';
}
}