umanit/easyadmin-tree-bundle
最新稳定版本:0.0.7
Composer 安装命令:
composer require umanit/easyadmin-tree-bundle
包简介
Plugin to add category tree features for EasyAdmin
关键字:
README 文档
README
Plugin to add category tree features for EasyAdmin
Features
- Display of content's entries as a tree structure on index page
- Filter content's entries through a tree sidebar on index page
- Provide a TreeField to manage tree structures on forms
Installation
$ composer require umanit/easyadmin-tree-bundle
Configuration
The templates paths needs to be declared in your Twig configuration :
twig: paths: '%kernel.project_dir%/vendor/umanit/easyadmin-tree-bundle/Resources/views': UmanitEasyAdminTreeBundle
This bundle relies on StofDoctrineExtensionsBundle, so make sure it is configured properly : documentation. You need to :
- add tree extension to your mapping :
doctrine: orm: entity_managers: default: mappings: gedmo_tree: type: annotation prefix: Gedmo\Tree\Entity dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Tree/Entity" alias: GedmoTree # (optional) it will default to the name set for the mapping is_bundle: false
- activate the tree extension :
stof_doctrine_extensions: default_locale: en_US orm: default: tree: true
Usage
Administer a category tree
Create you category entity by extending AbstractTreeItem :
<?php // src/Entity/Category.php namespace App\Entity; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Umanit\EasyAdminTreeBundle\Entity\AbstractTreeItem; #[ORM\Entity] #[ORM\Table(name: 'app_category')] class Category extends AbstractTreeItem { ... }
Create a CRUD controller for your categories by extending the TreeCrudController
<?php // src/Controller/Admin/MyTreeCrudController.php namespace App\Controller\Admin; use App\Entity\Category; use EasyCorp\Bundle\EasyAdminBundle\Config\Action; use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField; use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; use EasyCorp\Bundle\EasyAdminBundle\Field\SlugField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use Umanit\EasyAdminTreeBundle\Controller\TreeCrudController; use Umanit\EasyAdminTreeBundle\Field\TreeField; class MyTreeCrudController extends TreeCrudController { public static function getEntityFqcn(): string { // return your Category entity FQCN return Category::class; } protected function getEntityLabelProperty(): string { // return the property of your category to use as a label in tree display return 'name'; } }
Enable the Crud in your EasyAdmin Dashboard :
public function configureMenuItems(): iterable { return [ ... MenuItem::linkToCrud('Categories', 'fas fa-list', Category::class), ... ]; }
Add a tree sidebar
To enable the tree sidebar to an existing CRUDController, you have to make it extend AbstractCategorizedCrudController :
<?php // src/Controller/Admin/MediaCrudController.php namespace App\Controller\Admin; use App\Entity\Category; use App\Entity\Media; use Umanit\EasyAdminTreeBundle\Controller\AbstractCategorizedCrudController; class MediaCrudController extends AbstractCategorizedCrudController { public static function getEntityFqcn(): string { return Media::class; } public function configureCrud(Crud $crud): Crud { $crud = parent::configureCrud($crud); // ... } public static function getCategoryFqcn(): string { // The FQCN of the entity to use as a category (should extend AbstractTreeItem) return Category::class; } protected static function getCategoryPropertyName(): string { // the name of the category property for the entity managed by this CRUDController return 'category'; } protected function getDefaultCategoryId(): int { // The id of the category that will be used as default filter for the index page of your CRUD return $this->getCategoryRepository()->findOneBy(['parent' => null])->getId(); } }
Use TreeField in your forms
You just need to add the field in the EasyAdmin configureFields function :
<?php // src/Controller/Admin/MediaCrudController.php namespace App\Controller\Admin; use Umanit\EasyAdminTreeBundle\Field\TreeField; class MediaCrudController extends AbstractCategorizedCrudController { public function configureFields(string $pageName): iterable { return [ // ... TreeField::new('category', 'My category'), // ... ]; }
Screenshots
TODO
List of needed improvements :
- fold/unfold categories
- reorder category items with drag'n drop
- prefill category in TreeField with current category in the sidebar
- improve front (design, css)
统计信息
- 总下载量: 6.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 23
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-28


