定制 nucleos/sonata-auto-configure-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nucleos/sonata-auto-configure-bundle

最新稳定版本:1.4.0

Composer 安装命令:

composer require nucleos/sonata-auto-configure-bundle

包简介

Symfony Bundle that auto configures Sonata Admin.

README 文档

README

Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

Continuous Integration Code Coverage

Tries to auto configure your admin classes and extensions, so you don't have to.

This is a fork of the no longer maintained kunicmarko/sonata-auto-configure-bundle.

Documentation

Installation

1. Add dependency with Composer

composer require nucleos/sonata-auto-configure-bundle

2. Enable the bundle for all Symfony environments:

// bundles.php
return [
    //...
    Nucleos\SonataAutoConfigureBundle\SonataAutoConfigureBundle::class => ['all' => true],
];

Configuration

sonata_auto_configure:
    admin:
        suffix: Admin
        manager_type: orm
        label_catalogue: ~
        label_translator_strategy: ~
        translation_domain: ~
        group: ~
        pager_type: ~
    entity:
        namespaces:
            - { namespace: App\Entity, manager_type: orm }
    controller:
        suffix: Controller
        namespaces:
            - App\Controller\Admin

How does it work

This bundle tries to guess some stuff about your admin class. You only have to create your admin classes and be sure that the admin directory is included in auto discovery and that autoconfigure is enabled.

This bundle will tag your admin classes with sonata.admin, then we find all admin classes and if autoconfigure is enabled we take the class name. If you defined a suffix in the config (by default it is Admin) we remove it to get the name of the entity, so if you had CategoryAdmin we get Category.

After that we check if the Admin attribute is present, attributes have a higher priority than our guesses. If no attribute is defined or some of the values that are mandatory are not present we still try to guess.

First, we set the label and based on previous example it will be Category.

Then, we set the admin code which will be the service id, in our case it is the class name.

After, we try to find the Category entity in the list of namespaces you defined (by default it is just App\Entity). If the entity is not found an exception is thrown and you will probably need to use an attribute to define the entity. You can set the manager_type attribute per namespace.

By default we will take manager_type from attributes, if they are not present we will take it from the namespace definition. If you define the entity in your attribute but not the manager_type then we will take the manager type from the bundle configuration that will be available as a sonata_auto_configure.admin.manager_type parameter.

Then we try to guess a controller, same as for the entity we try to guess it in the list of namespaces but we add a suffix (as in most situations people name it CategoryController) that you can disable in configuration. If there is no controller we leave it as null and sonata will add its default controller.

And that is it. We have all the info we need for defining an admin class, if you used some of the other tag options when defining your admin class you will have to use attribute or register admin on your own with autoconfigure: false that would look like:

App\Admin\CategoryAdmin:
    arguments: [~, App\Entity\Category, ~]
    autoconfigure: false
    tags:
        - { name: sonata.admin, manager_type: orm, label: Category }
    public: true

Attribute

<?php

namespace App\Admin;

use Nucleos\SonataAutoConfigureBundle\Attribute\Admin;
use App\Controller\Admin\CategoryController;
use App\Entity\Category;
use Sonata\AdminBundle\Admin\AbstractAdmin;

#[Admin(
    label: "Category",
    managerType: "orm",
    group: "Category",
    showInDashboard: true,
    showMosaicButton: true,
    keepOpen: true,
    onTop: true,
    icon: "<i class: 'fa fa-user'></i>",
    labelTranslatorStrategy: "sonata.admin.label.strategy.native",
    labelCatalogue: "App",
    translationDomain: "messages",
    pagerType: "simple",
    controller: CategoryController::class,
    entity: Category::class,
    adminCode: "admin_code",
    autowireEntity: true,
    templates: [
        "list" => "admin/category/list.html.twig"
    ],
    children: ["app.admin.product"]
)]
final class CategoryAdmin extends AbstractAdmin
{
}

AdminExtension

<?php

namespace App\Admin;

use Nucleos\SonataAutoConfigureBundle\Attribute\AdminExtension;
use Sonata\AdminBundle\Admin\AbstractAdminExtension;

#[AdminExtension(
    global: true
)]
final class GlobalExtension extends AbstractAdminExtension
{
}
<?php

namespace App\Admin;

use Nucleos\SonataAutoConfigureBundle\Attribute\AdminExtension;
use Sonata\AdminBundle\Admin\AbstractAdminExtension;
use App\Admin\ActivityAdmin;

#[AdminExtension(
    target: ["app.admin.project", ActivityAdmin::class]
)]
final class SortableExtension extends AbstractAdminExtension
{
}

统计信息

  • 总下载量: 10.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固