runroom-packages / sortable-behavior-bundle
提供了一种对管理员列表进行排序的方法
0.19.1
2024-09-06 13:59 UTC
Requires
- php: ^8.1
- doctrine/dbal: ^3.6
- doctrine/doctrine-bundle: ^2.10
- doctrine/orm: ^2.19 || ^3.2
- doctrine/persistence: ^3.1
- symfony/config: ^5.4 || ^6.4 || ^7.1
- symfony/dependency-injection: ^5.4 || ^6.4 || ^7.1
- symfony/http-foundation: ^5.4 || ^6.4 || ^7.1
- symfony/http-kernel: ^5.4 || ^6.4 || ^7.1
- symfony/property-access: ^5.4 || ^6.4 || ^7.1
- symfony/translation: ^5.4 || ^6.4 || ^7.1
- twig/twig: ^3.0
Requires (Dev)
- dama/doctrine-test-bundle: ^8.0
- gedmo/doctrine-extensions: ^3.11
- knplabs/knp-menu-bundle: ^3.1
- matthiasnoback/symfony-config-test: ^5.1
- matthiasnoback/symfony-dependency-injection-test: ^5.1
- phpunit/phpunit: ^9.6
- psr/container: ^1.1 || ^2.0
- runroom-packages/testing: ^0.19.1
- sonata-project/admin-bundle: ^4.20
- sonata-project/doctrine-orm-admin-bundle: ^4.3
- symfony/browser-kit: ^5.4 || ^6.4 || ^7.1
- symfony/framework-bundle: ^5.4 || ^6.4 || ^7.1
- symfony/phpunit-bridge: ^7.1
- symfony/security-bundle: ^5.4 || ^6.4 || ^7.1
- symfony/twig-bundle: ^5.4 || ^6.4 || ^7.1
- zenstruck/foundry: ^1.38.2 || ^2.0
Conflicts
- gedmo/doctrine-extensions: <3.11
- sonata-project/admin-bundle: <4.20
- dev-master / 0.20.x-dev
- 0.19.1
- 0.19.0
- 0.18.0
- 0.17.2
- 0.17.1
- 0.17.0
- 0.16.1
- 0.16.0
- 0.15.7
- v0.15.6
- v0.15.5
- v0.15.4
- v0.15.3
- v0.15.2
- v0.15.1
- v0.15.0
- v0.14.1
- v0.14.0
- v0.13.3
- v0.13.2
- v0.13.1
- v0.13.0
- v0.12.0
- v0.11.1
- v0.11.0
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.1
- v0.7.0
- v0.6.9
- v0.6.8
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.1
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
This package is auto-updated.
Last update: 2024-09-10 10:09:53 UTC
README
此包提供定义可排序实体并在 Sonata Backoffice 中对其进行排序的能力。它受到了 pixSortableBehaviorBundle 的启发。
安装
打开命令行控制台,进入您的项目目录,然后执行以下命令以下载此包的最新稳定版本
composer require runroom-packages/sortable-behavior-bundle
启用包
然后,通过将其添加到项目 config/bundles.php
文件中注册的包列表中,启用包
// config/bundles.php
return [
// ...
Runroom\SortableBehaviorBundle\RunroomSortableBehaviorBundle::class => ['all' => true],
];
使用
此包会检查您是否正在使用 Gedmo Sortable 来处理实体排序,如果不是,它将使用默认的 ORM 实现,其中您需要手动在包的配置中添加实体。如果您正在使用 Gedmo,并且不想更改默认字段名 position
,则无需为此包进行任何配置。
我们提供了一个特质,这样您就可以轻松地将位置字段与 Gedmo 配置添加到您希望能够排序的每个实体中
# src/Entity/Example.php
namespace App\Entity;
use Runroom\SortableBehaviorBundle\Behaviors\Sortable;
class Example
{
use Sortable;
// ... rest of your class
}
然后,在您的管理类中,您可以添加 SortableAdminTrait
特质以在列表视图中对实体进行排序
# src/Admin/ExampleAdmin.php
namespace App\Admin;
use Runroom\SortableBehaviorBundle\Admin\SortableAdminTrait;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
class ExampleAdmin extends AbstractAdmin
{
use SortableAdminTrait;
protected function configureListFields(ListMapper $list): void
{
$list
// ... rest of your list fields
->add(ListMapper::NAME_ACTIONS, ListMapper::TYPE_ACTIONS, [
'actions' => [
// ... rest of your actions
'move' => [
'template' => '@RunroomSortableBehavior/sort.html.twig',
],
],
]);
}
}
就这样,您现在应该可以在管理类的列表视图中看到排序按钮。
配置
# config/packages/runroom_sortable_behavior.yaml
runroom_sortable_behavior:
# position_handler can be any service id that implements the PositionHandlerInterface
position_handler: Runroom\SortableBehaviorBundle\Service\GedmoPositionHandler # or Runroom\SortableBehaviorBundle\Service\ORMPositionHandler if gedmo is not found
position_field:
default: position # Default field name for the position
# Only needed when not using Gedmo
entities:
App\Entity\Foobar: order
App\Entity\Baz: rang
# Only needed when not using Gedmo
sortable_groups:
entities:
App\Entity\Baz: [group]
使用可拖动的列表代替上下按钮
为了使用可拖动的列表而不是上下按钮,请将 move
动作中的模板更改为 @RunroomSortableBehavior/sort_drag_drop.html.twig
。
protected function configureListFields(ListMapper $list): void
{
$list
// ... rest of your list fields
->add(ListMapper::NAME_ACTIONS, ListMapper::TYPE_ACTIONS, [
'actions' => [
// ... rest of your actions
'move' => [
'template' => '@RunroomSortableBehavior/sort_drag_drop.html.twig',
'enable_top_bottom_buttons' => true, // optional
],
],
]);
}
贡献
此包的源代码包含在 Runroom monorepo 中。我们欢迎在 runroom/runroom-packages 上为此包做出贡献。
许可证
此包受 MIT 许可证 的约束。