add menuitem aliases
This commit is contained in:
parent
70b39515ec
commit
9781bd561f
13 changed files with 713 additions and 212 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue