PHPackages                             kunicmarko/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. kunicmarko/sonata-auto-configure-bundle

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

kunicmarko/sonata-auto-configure-bundle
=======================================

Symfony Bundle that auto configures Sonata Admin.

0.7.1(7y ago)1632.7k5MITPHPPHP ^7.1

Since Aug 17Pushed 6y ago3 watchersCompare

[ Source](https://github.com/kunicmarko20/SonataAutoConfigureBundle)[ Packagist](https://packagist.org/packages/kunicmarko/sonata-auto-configure-bundle)[ Docs](https://github.com/kunicmarko20/SonataAutoConfigureBundle)[ RSS](/packages/kunicmarko-sonata-auto-configure-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (17)Versions (9)Used By (0)

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

[](#sonataautoconfigurebundle)

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

[![PHP Version](https://camo.githubusercontent.com/2dcf2757d7a2ae7d144c6e7d9b63bd3383509e6b70bacccb3bd8ad04d1c2541c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e312d626c75652e737667)](https://img.shields.io/badge/php-%5E7.1-blue.svg)[![Latest Stable Version](https://camo.githubusercontent.com/1fe33a712b0ed4ee4a70687c7fd7286e56d318a388c514b08d04413457d9c677/68747470733a2f2f706f7365722e707567782e6f72672f6b756e69636d61726b6f2f736f6e6174612d6175746f2d636f6e6669677572652d62756e646c652f762f737461626c65)](https://packagist.org/packages/kunicmarko/sonata-auto-configure-bundle)[![Latest Unstable Version](https://camo.githubusercontent.com/04d0fe710512f73a2869804a212c68d29857fc2312d01237a534b4f49e1011df/68747470733a2f2f706f7365722e707567782e6f72672f6b756e69636d61726b6f2f736f6e6174612d6175746f2d636f6e6669677572652d62756e646c652f762f756e737461626c65)](https://packagist.org/packages/kunicmarko/sonata-auto-configure-bundle)

[![Build Status](https://camo.githubusercontent.com/e19fa106701e7f8a2963bccdde751b953e7ee6cbe8da6eaed67a14fc5acbe45c/68747470733a2f2f7472617669732d63692e6f72672f6b756e69636d61726b6f32302f536f6e6174614175746f436f6e66696775726542756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kunicmarko20/SonataAutoConfigureBundle)[![Coverage Status](https://camo.githubusercontent.com/7452ee25a99baade01411a1a1e39adf97039cbe4f0e7a5399c4339127637f6d4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6b756e69636d61726b6f32302f536f6e6174614175746f436f6e66696775726542756e646c652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/kunicmarko20/SonataAutoConfigureBundle?branch=master)

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

[](#documentation)

- [Installation](#installation)
- [Configuration](#configuration)
- [How does it work](#how-does-it-work)
- [Annotation](#annotation)
    - [AdminOptions](#adminoptions)
    - [AdminExtensionOptions](#adminextensionoptions)

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

[](#installation)

**1.** Add dependency with Composer

```
composer require kunicmarko/sonata-auto-configure-bundle
```

**2.** Enable the bundle for all Symfony environments:

```
// bundles.php
return [
    //...
    KunicMarko\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 `AdminOption` annotation is present, annotations have a higher priority than our guesses. If no annotation 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 annotation to define the entity. You can set the `manager_type` attribute per namespace.

By default we will take `manager_type` from annotations, if they are not present we will take it from the namespace definition. If you define the entity in your annotation 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 Annotation 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
```

Since your admin class is autowired you can still use setter injection but you have to add a `@required` annotation:

```
/**
 * @required
 */
public function setSomeService(SomeService $someService)
{
    $this->someService = $someService;
}
```

Annotation
----------

[](#annotation)

### AdminOptions

[](#adminoptions)

```
