src/Entity/TranslatorEntry.php line 56
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\Get,
ApiPlatform\Metadata\GetCollection,
ApiPlatform\Metadata\Post,
ApiPlatform\Metadata\Put,
ApiPlatform\Metadata\Delete,
ApiPlatform\Metadata\ApiFilter,
ApiPlatform\Doctrine\Orm\Filter\SearchFilter,
ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\OrdTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslatableTrait,
App\Entity\Interface\TranslatableInterface,
App\Entity\Interface\OrderableInterface,
App\Enum\Language,
App\Repository\TranslatorEntryRepository;
use App\StateProcessor\TranslatorEntryProcessor;
#[ApiResource(
description: 'Translator entries',
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
'read:' . self::class . 'Translation'
]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . self::class . '")',
order: ['ord' => 'desc'],
operations: [
new GetCollection(),
new Post(processor: TranslatorEntryProcessor::class),
new Get(),
new Put(processor: TranslatorEntryProcessor::class),
new Delete(processor: TranslatorEntryProcessor::class),
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(SearchFilter::class, properties: ['translations.title' => 'partial', 'code' => 'partial'])]
#[ApiFilter(OrderFilter::class, properties: ['code', 'ord'])]
#[ORM\Entity(repositoryClass: TranslatorEntryRepository::class)]
class TranslatorEntry implements TranslatableInterface, OrderableInterface
{
use IdTrait,
UuidTrait,
OrdTrait,
TimestampableTrait,
TranslatableTrait;
#[ApiProperty(description: 'Code of entry')]
#[Groups(['read', 'write'])]
#[Assert\NotBlank]
#[ORM\Column(type: Types::STRING, length: 191, unique: true)]
private string $code;
public function __construct(string $code)
{
$this->setUuid();
$this->code = $code;
$this->translations = new ArrayCollection();
foreach (Language::DEFAULT_SITE as $lang) {
new TranslatorEntryTranslation($this, $lang);
}
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
}