定制 edumedia/tag-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

edumedia/tag-bundle

最新稳定版本:0.1.19

Composer 安装命令:

composer require edumedia/tag-bundle

包简介

README 文档

README

Rationale

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.

How to

Install bundle

composer require edumedia/tag-bundle

Create Tag class

<?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;

}

Create Tagging class

<?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;

}

Make entity taggable

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;
    
    // (...)
}

Define service arguments

# config/services.yaml
services:
  # (...)
  eduMedia\TagBundle\Service\TagService:
    arguments:
      - 'App\Entity\Tag'
      - 'App\Entity\Tagging'

Migrate, to create tables

bin/console make:migration
bin/console doctrine:migrations:migrate

Install assets

bin/console assets:install

Features

  • Most features are packed in eduMedia\TagBundle\Service\TagService (not documented yet, but should be self-explanatory)
  • If symfony/console is installed, a edumedia:tag:create command is available
  • If symfony/twig-bundle is installed, tag_service is globally available
  • If symfony/form is installed, eduMedia\TagBundle\Form\Type\TagType is available
  • If using easycorp/easyadmin-bundle, a eduMedia\TagBundle\Admin\Field\TagField is available

TODO

  • Automated tests (help appreciated)

统计信息

  • 总下载量: 6.09k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-19