Implement snip tags with very elegant tags form

This commit is contained in:
Tim
2025-05-10 20:06:16 +02:00
parent 47ea226ed7
commit e2bd1a7c3b
7 changed files with 325 additions and 8 deletions

View File

@ -39,9 +39,16 @@ class Snip
#[ORM\Column]
private bool $archived = false;
/**
* @var Collection<int, Tag>
*/
#[ORM\ManyToMany(targetEntity: Tag::class, mappedBy: 'snips')]
private Collection $tags;
public function __construct()
{
$this->snipContents = new ArrayCollection();
$this->tags = new ArrayCollection();
}
public function __toString(): string
@ -160,4 +167,31 @@ class Snip
return $this;
}
/**
* @return Collection<int, Tag>
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tag $tag): static
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
$tag->addSnip($this);
}
return $this;
}
public function removeTag(Tag $tag): static
{
if ($this->tags->removeElement($tag)) {
$tag->removeSnip($this);
}
return $this;
}
}