artgris / easy-admin-commands-bundle

此包已被弃用且不再维护。未建议替代包。

EasyAdminBundle 配置生成器

安装: 112

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 2

分支: 0

开放问题: 6

类型:symfony-bundle


README

安装

composer require artgris/easy-admin-commands-bundle

配置

在 config/packages

添加 artgris_easy_commands.yaml

artgris_easy_admin_commands:
    dir: '%kernel.project_dir%/config/packages/easy_admin/entities/'

并创建新的 config/packages/easy_admin/ 目录

生成 easyadmin 配置

php bin/console artgris:easyadmin:export

编辑 easyadmin yaml

# config/packages/easy_admin.yaml
imports:
    - { resource: easy_admin/ }

基本配置

示例实体

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity()
 */
class Example
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var string
     * @ORM\Column(type="string", length=255)
     * @Assert\Length(max=255)
     * @Assert\NotBlank
     */
    private $name;

    /**
     * @var string
     * @ORM\Column(type="text", nullable=true)
     */
    private $description;

    /**
     * @var \DateTime
     * @ORM\Column(type="date")
     * @Assert\Date()
     * @Assert\NotBlank()
     */
    private $date;
    
    ...
artgris_easy_admin_commands:
    dir: '%kernel.project_dir%/config/packages/easy_admin/entities/'
    namespaces:
        - 'App\Entity'
    types:
        text:
            type_options:
                attr: {class: 'tinymce'}
        date:
            type: date
            type_options:
                attr:
                    class: 'flatpickr'
                    autocomplete: 'off'
                widget: 'single_text'
                format: 'dd/MM/yyyy'

    list:
        excluded: 
            - id
    form:
        excluded: 
            - id
php bin/console artgris:easyadmin:export

生成配置

# entities/example.yaml :
easy_admin:
    entities:
        example:
            class: App\Entity\Example
            list:
                fields:
                    - name
                    - description
                    - date
            form:
                fields:
                    - name
                    - { property: description, type_options: { attr: { class: tinymce } } }
                    - { property: date, type: date, type_options: { attr: { class: flatpickr, autocomplete: 'off' }, widget: single_text, format: dd/MM/yyyy } }
            edit:
                fields:
                    - name
                    - { property: description, type_options: { attr: { class: tinymce } } }
                    - { property: date, type: date, type_options: { attr: { class: flatpickr, autocomplete: 'off' }, widget: single_text, format: dd/MM/yyyy } }
            new:
                fields:
                    - name
                    - { property: description, type_options: { attr: { class: tinymce } } }
                    - { property: date, type: date, type_options: { attr: { class: flatpickr, autocomplete: 'off' }, widget: single_text, format: dd/MM/yyyy } }

完整配置

artgris_easy_admin_commands:
    dir: '%kernel.project_dir%/config/packages/easy_admin/entities/'
    namespaces:
        - 'App\Entity'
    entities:
        included:
            - 'App\Entity\Example'
        excluded:
            - 'App\Entity\User'
    types:
        text:
            type_options:
                attr: {class: 'tinymce'}
        image:
            type: image
            base_path: '%app.path.product_images%'
    regex:
        ^image*: image
        ...
        
    list:
        included: 
            - name
            - ...
        excluded: 
            - id
            - ...
        position: 
            - name
            - ...
        sort:
            - ['createdAt', 'desc']
            - ...
    form:
        included: 
            - name
            - ...
        excluded: 
            - id
            - ...
        position: 
            - name
            - ...

dir : 配置生成的文件夹

namespaces : 实体搜索命名空间

实体

  • included : 仅包括这些实体
  • excluded : 排除以下实体

types : 如果找到 doctrine 类型 元数据类型,则生成器将使用关联的配置

regex : 根据名称和正则表达式强制指定实体字段的类型

列表

  • included : 仅在列表中包括这些字段(如果它们存在于实体中)
  • excluded : 从列表中排除以下字段(如果它们存在于实体中)
  • position : 字段在列表中的位置(如果它们存在于实体中)
  • sort : 按以下字段排序(列表中首先找到的)

form : 与列表相同

导出特定实体

⚠️ 此命令覆盖配置参数 'entities' ('included/excluded')

php bin/console artgris:easyadmin:export 'App\Entity\Example'
or  
php bin/console artgris:easyadmin:export App\\Entity\\Example