aliocza / sortable-ui-bundle
提供了一种排序管理列表的方法
Requires
- php: >=5.3.0
- symfony/form: >=2.1
- symfony/framework-bundle: >=2.1
Requires (Dev)
- gedmo/doctrine-extensions: >=2.2
Suggests
- sonata-project/admin-bundle: Can be easily integrated with Sonata Admin bundle
- stof/doctrine-extensions-bundle: 1.1.*@dev
This package is not auto-updated.
Last update: 2024-09-15 01:46:39 UTC
README
这是为了更好的GUI而全面重写的。
原始的 'bundle' 由 https://github.com/pix-digital/pixSortableBehaviorBundle 提供
原始的 'cookbook' 由 https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/doc/cookbook/recipe_sortable_listing.rst 提供
未来的功能
-
多级拖放
-
改进性能代码
-
注释代码
配置
# app/config/config.yml
aliocza_sortable_ui:
db_driver: orm # default value : orm (orm is only supported)
position_field:
default: sort #default value : position
entities:
AppBundle/Entity/Foobar: order
AppBundle/Entity/Baz: rang
Sonata Admin 的 cookbooks
先决条件
-
您已经安装并运行了 SonataAdmin 和 DoctrineORM
-
您已经有一个实体类,您想为其实现排序功能。为了示例,我们将称之为
Client
。 -
您已经设置了一个管理员,在这个例子中,我们将称之为
ClientAdmin
捆绑
- 在您的项目中安装
gedmo/doctrine-extensions
捆绑包(在stof/doctrine-extensions-bundle
中检查以简化项目中的集成)并启用配置中的排序功能。有关如何安装捆绑包的信息:https://symfony.com.cn/doc/current/bundles/StofDoctrineExtensionsBundle/index.html - 在您的项目中安装
aliocza/sortable-ui-bundle
食谱
首先,我们将在我们的 Client
实体中添加一个位置字段。
use Gedmo\Mapping\Annotation as Gedmo;
// ...
/**
* @Gedmo\SortablePosition
* @ORM\Column(name="position", type="integer")
*/
private $position;
然后我们需要注入 Sortable 监听器。如果您只启用了 Gedmo 捆绑包,您只需将监听器添加到您的 config.yml 中并跳过此步骤。
services:
gedmo.listener.sortable:
class: Gedmo\Sortable\SortableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ "@annotation_reader" ] ]
在我们的 ClientAdmin
中,我们将在 configureListFields
方法中添加一个自定义操作,并使用 alioczaSortableUiBundle
中提供的默认 twig 模板。
$listMapper
->add('_action', 'actions', array(
'actions' => array(
'drag' => array(
'template' => 'AlioczaSortableUiBundle:Default:drag.html.twig'
),
)
)
);
为了为这些操作添加新的路由,我们还添加了以下方法,并覆盖了添加按钮的模板
<?php
// src/AppBundle/Admin/ClientAdmin.php
namespace AppBundle/Admin;
use Sonata\AdminBundle\Route\RouteCollection;
// ...
private $positionService;
protected $datagridValues = array(
'_sort_order' => 'ASC',
'_sort_by' => 'position',
);
protected function configureRoutes(RouteCollection $collection) {
// ...
$collection->add('drag', 'drag');
}
public function configure() {
$this->setTemplate('list', 'AlioczaSortableUiBundle:CRUD:base_list.html.twig');
}
public function setPositionService(\Aliocza\SortableUiBundle\Services\PositionHandler $positionHandler) {
$this->positionService = $positionHandler;
}
现在,您可以将您的 services.yml
更新为使用 alioczaSortableUiBundle
的处理器提供程序
services:
app.admin.client:
class: AppBundle\Admin\ClientAdmin
tags:
- { name: sonata.admin, manager_type: orm, label: "Clients" }
arguments:
- ~
- AppBundle\Entity\Client
- 'AlioczaSortableUiBundle:SortableUiAdmin' # define the new controller via the third argument
calls:
- [ setTranslationDomain, [AppBundle]]
- [ setPositionService, ['@aliocza_sortable_ui.position']]