Revival of https://github.com/FabienPennequin/FPNTagBundle for Symfony 6+ and PHP 8+.
Note: The main difference with fpn/tag-bundle is that taggable entities do not hold their tags, they're only available through the TagService.
composer require edumedia/tag-bundle
<?php
// src/Entity/Tag.php
namespace App\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use eduMedia\TagBundle\Entity\TagInterface;
use eduMedia\TagBundle\Entity\TagTrait;
#[ORM\Entity]
#[ORM\Table(name: 'tag')]
class Tag implements TagInterface
{
use TagTrait;
#[ORM\OneToMany(mappedBy: 'tag', targetEntity: 'App\Entity\Tagging', fetch: 'EAGER')]
protected ?Collection $tagging = null;
}
<?php
// src/Entity/Tagging.php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use eduMedia\TagBundle\Entity\TaggingInterface;
use eduMedia\TagBundle\Entity\TaggingTrait;
use eduMedia\TagBundle\Entity\TagInterface;
#[ORM\Entity]
#[ORM\Table(name: 'tagging')]
class Tagging implements TaggingInterface
{
use TaggingTrait;
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: 'App\Entity\Tag', inversedBy: 'tagging')]
protected TagInterface $tag;
}
Here is a User example:
<?php
// src/Entity/User
namespace App\Entity;
use eduMedia\TagBundle\Entity\TaggableInterface;
use eduMedia\TagBundle\Entity\TaggableTrait;
class User implements /* (...) */ TaggableInterface
{
use TaggableTrait;
// (...)
}
# config/services.yaml
services:
# (...)
eduMedia\TagBundle\Service\TagService:
arguments:
- 'App\Entity\Tag'
- 'App\Entity\Tagging'
bin/console make:migration
bin/console doctrine:migrations:migrate
bin/console assets:install
eduMedia\TagBundle\Service\TagService (not documented yet, but should be self-explanatory)symfony/console is installed, a edumedia:tag:create command is availablesymfony/twig-bundle is installed, tag_service is globally availablesymfony/form is installed, eduMedia\TagBundle\Form\Type\TagType is availableeasycorp/easyadmin-bundle, a eduMedia\TagBundle\Admin\Field\TagField is availableHow can I help you explore Laravel packages today?