tastaturberuf/contao-entity-attributes-bundle

使用PHP 8+ 属性来配置DCA

dev-main 2021-10-15 12:36 UTC

This package is auto-updated.

Last update: 2024-09-15 18:47:05 UTC


README

用法

将映射类型设置为 attribute 并定义实体所在位置。

# config/services.yaml

doctrine:
    orm:
        mappings:
            App:
                type: attribute
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'

使用 entity.datacontainer 标记您的实体。

# config/services.yaml

App\Entity\:
    resource: '../src/Entity/'
    tags: ['entity.datacontainer']

最小配置

use Doctrine\ORM\Mapping as ORM;
use Tastaturberuf\ContaoEntityAttributesBundle\Attribute as DCA;

#[ORM\Entity]
#[ORM\Table('tl_my_table_name')]
#[DCA\DataContainer]
class MyEntity
{

}

示例配置

use Doctrine\ORM\Mapping as ORM;
use Tastaturberuf\ContaoEntityAttributesBundle\Attribute as DCA;

#[ORM\Entity]         
#[ORM\Table('my_entity')]
#[DCA\DataContainer]
#[DCA\Label(fields: ['id', 'tstamp', 'name', 'alias'], showColumns: true)]
#[DCA\Palettes(legends: ['title', 'config', 'custom'])]
#[DCA\GlobalOperationAll]
#[DCA\OperationEdit]
#[DCA\OperationDelete]
#[DCA\OperationShow]
// there are more Attributes available
class MyEntity
{
    #[DCA\Field(exclude: false)]
    private int $id;

    #[ORM\Column('my_custom_name', nullable: true)]
    #[DCA\Field(search: true, sorting: true)]
    #[DCA\Palette('title')]
    // there are more Attributes available
    private string $name;
}

自定义属性

只需像PHP 8命名参数一样输入您的自定义属性。

use Tastaturberuf\ContaoEntityAttributesBundle\Attribute as DCA;

#[DCA\DataContainer(my_custom_key: 'my_custom_value')]
class myEntity
{

}

注意事项

  • Field::$exclude 默认为 true
  • Sorting::$panelLayout 默认为 'filter;sort,search,limit'
  • 不要使用 $__custom_properties 参数,只需写出您的[自定义属性](#Custom properties)。

待办事项

  • 编写基本用法文档。
  • 为常用配置的字段添加辅助属性,如 w50: true
  • EntityDataContainerInterface 创建 CompilerPass 以自动标记实体。
  • 重构 PalettePalettes 属性以更好地处理。也许不需要 MetaPalettes 依赖。
  • 从Doctrine映射配置字段评估,如 minLengthmaxLength 等。