kachnitel/entity-components-bundle
Composer 安装命令:
composer require kachnitel/entity-components-bundle
包简介
Reusable Symfony Live Components for entity management (tags, attachments, comments, inline-edit fields)
README 文档
README
Reusable Symfony Live Components for entity management: tags, file attachments, comments, relationship dropdowns, and a full set of inline-edit field components that work with any Doctrine entity.
Quick Start
1. Install
composer require kachnitel/entity-components-bundle
2. Map interfaces to your concrete classes
For each bundle feature you use, add one line to config/packages/doctrine.yaml:
# config/packages/doctrine.yaml doctrine: orm: resolve_target_entities: # Add only the lines relevant to features you use: Kachnitel\EntityComponentsBundle\Interface\TagInterface: App\Entity\Tag Kachnitel\EntityComponentsBundle\Interface\AttachmentInterface: App\Entity\Attachment
3. Use the traits and drop in components
// Any entity that needs tags — no extra ORM mapping required class Product implements TaggableInterface { use TaggableTrait; public function __construct() { $this->initializeTags(); } }
{{# Inline-edit a text field — any entity property with a setter #}}
<twig:K:Entity:Field:String :entity="user" property="name" />
{{# Tag management #}}
<twig:K:Entity:TagManager :entity="product" tagClass="App\\Entity\\Tag" />
{{# File attachments #}}
<twig:K:Entity:AttachmentManager :entity="product" attachmentClass="App\\Entity\\Attachment" />
{{# Comments #}}
<twig:K:Entity:CommentsManager :entity="article" commentClass="App\\Entity\\Comment" />
{{# Relationship / enum dropdown #}}
<twig:K:Entity:SelectRelationship :entity="order" property="status" />
What's Next?
Inline-edit any field
Level 1: Drop in a field component — click ✎ to edit, save, or cancel:
<twig:K:Entity:Field:String :entity="user" property="name" /> <twig:K:Entity:Field:Int :entity="product" property="stock" /> <twig:K:Entity:Field:Bool :entity="user" property="active" /> <twig:K:Entity:Field:Date :entity="event" property="startsAt" /> <twig:K:Entity:Field:Enum :entity="order" property="status" />
Level 2: Association fields with live search:
<twig:K:Entity:Field:Relationship :entity="product" property="category" /> <twig:K:Entity:Field:Collection :entity="post" property="tags" />
Level 3: Add Symfony Validator constraints to the entity — validation runs automatically before flushing:
#[Assert\NotBlank] #[Assert\Length(max: 100)] private ?string $name = null;
Level 4: Control who can edit by overriding EditabilityResolverInterface:
Kachnitel\EntityComponentsBundle\Components\Field\EditabilityResolverInterface: alias: App\Field\MyEditabilityResolver
Details: Inline-Edit Guide
Tag management
Level 1: Implement TagInterface and TaggableInterface, drop in the component:
<twig:K:Entity:TagManager :entity="product" tagClass="App\\Entity\\Tag" />
Level 2: Read-only badge display:
<twig:K:Entity:TagManager :entity="product" tagClass="App\\Entity\\Tag" :readOnly="true" />
Level 3: Colored categories — return a hex color from getCategoryColor() on your Tag entity. Text color is flipped automatically for contrast.
Details: Tags Guide
File attachments
Level 1: Register a FileHandlerInterface service, implement AttachableInterface, drop in the component:
<twig:K:Entity:AttachmentManager :entity="product" attachmentClass="App\\Entity\\Attachment" />
Level 2: Read-only display, custom collection property:
:config="{ readOnly: true, property: 'media' }"
Level 3: Per-attachment tagging:
:config="{ tagClass: 'App\\Entity\\Tag' }"
Details: Attachments Guide
Comments
Level 1: Implement CommentInterface and CommentableInterface, drop in the component:
<twig:K:Entity:CommentsManager :entity="article" commentClass="App\\Entity\\Comment" />
Level 2: Read-only display, custom collection property:
:config="{ readOnly: true, property: 'notes' }"
Level 3: Limit text length — add a MAX_TEXT_LENGTH constant to your Comment entity and the textarea maxlength is set automatically.
Details: Comments Guide
Relationship / enum dropdown
Level 1: Works out of the box for any entity relation or backed enum:
<twig:K:Entity:SelectRelationship :entity="order" property="region" />
Level 2: Access control, placeholder, label:
:config="{
role: 'ROLE_EDITOR',
placeholder: '— Select Region —',
}"
Level 3: Filter records or use a custom repository method:
:config="{ filter: { active: true } }"
:config="{ repositoryMethod: 'findActive' }"
Details: SelectRelationship Guide
Components at a glance
| Component | Tag | Description |
|---|---|---|
TagManager |
K:Entity:TagManager |
Colored tag badges with category grouping |
AttachmentManager |
K:Entity:AttachmentManager |
File upload and attachment list |
CommentsManager |
K:Entity:CommentsManager |
Threaded comments with delete confirmation |
SelectRelationship |
K:Entity:SelectRelationship |
Eager dropdown for small option sets and enums |
StringField |
K:Entity:Field:String |
Inline text edit |
IntField |
K:Entity:Field:Int |
Inline integer edit |
FloatField |
K:Entity:Field:Float |
Inline decimal edit |
BoolField |
K:Entity:Field:Bool |
Inline checkbox toggle |
DateField |
K:Entity:Field:Date |
Inline date / datetime / time edit |
EnumField |
K:Entity:Field:Enum |
Inline dropdown for PHP backed enums |
RelationshipField |
K:Entity:Field:Relationship |
Live-search inline editor for ManyToOne / OneToOne |
CollectionField |
K:Entity:Field:Collection |
Live-search inline editor for ManyToMany / OneToMany |
Documentation
| Guide | Description |
|---|---|
| Inline-Edit Fields | All field types, validation, editability control, display override |
| Tags | TagManager setup, categories, colors |
| Attachments | AttachmentManager setup, FileHandlerInterface, template blocks |
| Comments | CommentsManager setup, author attribution, text limits |
| SelectRelationship | Dropdown for relations and enums, access control, filtering |
Requirements
- PHP 8.2+
- Symfony 6.4, 7.x, or 8.x
- Doctrine ORM
- Symfony UX Live Component
License
MIT
统计信息
- 总下载量: 474
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-07