add menuitem aliases
All checks were successful
/ ls (pull_request) Successful in 2m42s
/ ls (release) Successful in 50s
/ ls (push) Successful in 2m27s

This commit is contained in:
lubiana 2025-01-25 02:14:39 +01:00
parent 70b39515ec
commit 9781bd561f
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
13 changed files with 713 additions and 212 deletions

View file

@ -4,6 +4,8 @@ namespace App\Entity;
use App\Repository\MenuItemRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
@ -22,13 +24,24 @@ class MenuItem
#[ORM\Column(nullable: true)]
private DateTimeImmutable|null $deletedAt = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'aliases')]
private self|null $aliasOf = null;
/**
* @var Collection<int, self>
*/
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'aliasOf')]
private Collection $aliases;
public function __construct(
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = new Ulid
) {}
) {
$this->aliases = new ArrayCollection;
}
public function getId(): Ulid|null
{
@ -81,4 +94,44 @@ class MenuItem
return $this;
}
public function getAliasOf(): self|null
{
return $this->aliasOf;
}
public function setAliasOf(self|null $aliasOf): static
{
$this->aliasOf = $aliasOf;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getAliases(): Collection
{
return $this->aliases;
}
public function addAlias(self $alias): static
{
if (! $this->aliases->contains($alias)) {
$this->aliases->add($alias);
$alias->setAliasOf($this);
}
return $this;
}
public function removeAlias(self $alias): static
{
// set the owning side to null (unless already changed)
if ($this->aliases->removeElement($alias) && $alias->getAliasOf() === $this) {
$alias->setAliasOf(null);
}
return $this;
}
}