Implement snip tags with very elegant tags form
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user