vivait / tag-bundle
Tag Bundle
Installs: 1 906
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 7
Forks: 2
Open Issues: 0
Requires
- fpn/tag-bundle: ~0.9
This package is auto-updated.
Last update: 2024-01-14 18:29:01 UTC
README
This bundle requires FPN\TagBundle
AppKernel
new FPN\TagBundle\FPNTagBundle(),
new Vivait\TagBundle\VivaitTagBundle(),
Composer.json
"require": { //... "vivait/tag-bundle":"dev-master" },
Usage: Entities need to implement Vivait/Entity/Taggable and the following methods
public function getTags()
{
$this->tags = $this->tags ?: new ArrayCollection();
return $this->tags;
}
public function getTaggableType()
{
return 'finance_tag';
}
public function getTaggableId()
{
return $this->getId();
}
To use you must first init the tagging manager:
$tagManager = $this->get('fpn_tag.tag_manager');
$tagManager->loadTagging($entity);
When adding a new tag - be aware that you can't add duplicates without Doctrine kicking off about a duplicate key
$tag = $tm->loadOrCreateTag($this->tag);
if(!$finance->getTags()->contains($tag)) {
$tm->addTag($tag,$finance);
}
$em->persist($finance);
$em->flush();
$tm->saveTagging($finance);
When removing a tag - you must still load the tagging manager
$tm = $this->tag_manager;
$em = $this->em;
$tm->loadTagging($finance);
$tag = $tm->loadOrCreateTag($this->tag);
$tm->removeTag($tag, $finance);
$em->persist($finance);
$em->flush();
$tm->saveTagging($finance);