PHPackages                             nucleos/sonata-auto-configure-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. nucleos/sonata-auto-configure-bundle

ActiveSymfony-bundle[Admin Panels](/categories/admin)

nucleos/sonata-auto-configure-bundle
====================================

Symfony Bundle that auto configures Sonata Admin.

1.3.0(6mo ago)310.5k1[3 PRs](https://github.com/nucleos/SonataAutoConfigureBundle/pulls)MITPHPPHP ^8.3CI passing

Since Feb 4Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/nucleos/SonataAutoConfigureBundle)[ Packagist](https://packagist.org/packages/nucleos/sonata-auto-configure-bundle)[ Docs](https://nucleos.rocks)[ GitHub Sponsors](https://github.com/sponsors/core23)[ Fund](https://ko-fi.com/core23)[ RSS](/packages/nucleos-sonata-auto-configure-bundle/feed)WikiDiscussions 1.3.x Synced 1mo ago

READMEChangelog (4)Dependencies (10)Versions (12)Used By (0)

SonataAutoConfigureBundle
=========================

[](#sonataautoconfigurebundle)

[![Latest Stable Version](https://camo.githubusercontent.com/b27eb149d0cdeb8307b9ae324fe123a676c429f26eee6686a6b9610019f99495/68747470733a2f2f706f7365722e707567782e6f72672f6e75636c656f732f736f6e6174612d6175746f2d636f6e6669677572652d62756e646c652f762f737461626c65)](https://packagist.org/packages/nucleos/sonata-auto-configure-bundle)[![Latest Unstable Version](https://camo.githubusercontent.com/675188a8f772a13bcff1e9eed4980bcc857cf13aea87b0e616873753c2e29af4/68747470733a2f2f706f7365722e707567782e6f72672f6e75636c656f732f736f6e6174612d6175746f2d636f6e6669677572652d62756e646c652f762f756e737461626c65)](https://packagist.org/packages/nucleos/sonata-auto-configure-bundle)[![License](https://camo.githubusercontent.com/19b71f3339e5806b1b22585f0c71aa6f8af099de0df48bb37c19886e6f616572/68747470733a2f2f706f7365722e707567782e6f72672f6e75636c656f732f736f6e6174612d6175746f2d636f6e6669677572652d62756e646c652f6c6963656e7365)](LICENSE.md)

[![Total Downloads](https://camo.githubusercontent.com/1c7097385993c65f23f5a71f710e7536a2e58ac611755418f875f5bef370d0f3/68747470733a2f2f706f7365722e707567782e6f72672f6e75636c656f732f736f6e6174612d6175746f2d636f6e6669677572652d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/nucleos/sonata-auto-configure-bundle)[![Monthly Downloads](https://camo.githubusercontent.com/3c07062a1e6d4f26fe2208ff32cd23f656a4bed53f7405a57ecebd14aca3b53c/68747470733a2f2f706f7365722e707567782e6f72672f6e75636c656f732f736f6e6174612d6175746f2d636f6e6669677572652d62756e646c652f642f6d6f6e74686c79)](https://packagist.org/packages/nucleos/sonata-auto-configure-bundle)[![Daily Downloads](https://camo.githubusercontent.com/6f701d12fca22aa2d97310c0660b3f903214f71088cefd82ed30f624432bbd85/68747470733a2f2f706f7365722e707567782e6f72672f6e75636c656f732f736f6e6174612d6175746f2d636f6e6669677572652d62756e646c652f642f6461696c79)](https://packagist.org/packages/nucleos/sonata-auto-configure-bundle)

[![Continuous Integration](https://github.com/nucleos/SonataAutoConfigureBundle/actions/workflows/continuous-integration.yml/badge.svg?event=push)](https://github.com/nucleos/SonataAutoConfigureBundle/actions?query=workflow%3A%22Continuous+Integration%22+event%3Apush)[![Code Coverage](https://camo.githubusercontent.com/cc4d74a6c4c0ef79175544050409ea8b46c887e1a789679d6168d82d9763db17/68747470733a2f2f636f6465636f762e696f2f67682f6e75636c656f732f536f6e6174614175746f436f6e66696775726542756e646c652f67726170682f62616467652e737667)](https://codecov.io/gh/nucleos/SonataAutoConfigureBundle)

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](https://github.com/kunicmarko20/SonataAutoConfigureBundle).

Documentation
-------------

[](#documentation)

- [Installation](#installation)
- [Configuration](#configuration)
- [How does it work](#how-does-it-work)
- [Attribute](#attribute)

Installation
------------

[](#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
-------------

[](#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
----------------

[](#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
---------

[](#attribute)

```
