Skip to content

Commit

Permalink
Add autoconfigure docs (sonata-project#5436)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunicmarko20 authored and greg0ire committed Jan 19, 2019
1 parent b2d7408 commit 3ed0f9c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"suggest": {
"jms/di-extra-bundle": "Annotations for Admin definition",
"jms/translation-bundle": "Extract message keys from Admins",
"kunicmarko/sonata-auto-configure-bundle": "Auto configures Admin classes",
"sensio/generator-bundle": "Add sonata:admin:generate command",
"sonata-project/intl-bundle": "Add localized date and number into the list"
},
Expand Down
87 changes: 87 additions & 0 deletions docs/cookbook/recipe_auto_configure_admin_classes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
Auto Configuring Admin Classes
==============================

If you have a lot of admin classes and don't want to write all the service
definitions or if maybe you just don't like writing configuration and want
everything set up for you, this bundle will allow you not to do that.

Download the SonataAutoConfigureBundle
--------------------------------------

.. code-block:: bash
composer require kunicmarko/sonata-auto-configure-bundle
How to use
----------

The only thing you need to do is add the configuration for this bundle:

.. code-block:: yaml
# config/packages/sonata_auto_configure.yaml
sonata_auto_configure:
admin:
suffix: Admin
manager_type: orm
entity:
namespaces:
- { namespace: App\Entity, manager_type: orm }
controller:
suffix: Controller
namespaces:
- App\Controller\Admin
.. note::

Be sure that the admin directory is included in
auto discovery and that autoconfigure is enabled.

This configuration basically means, find all admin classes,
remove the ``Admin`` suffix and try to find an entity with the
same name in ``App\Entity`` namespace and add the ``orm`` ``manager_type``.
After, try to find the controllers in ``App\Controller\Admin`` but
replace the ``Admin`` suffix for ``Controller``.

If you are interested in more details on how this bundle works, read it `here`_.


Annotations
-----------

Annotations have a higher priority than bundle guesses, so if you are not happy
with something just add the annotation to your admin class::


namespace App\Admin;

use App\Controller\Admin\CategoryController;
use App\Entity\Category;
use KunicMarko\SonataAutoConfigureBundle\Annotation as Sonata;
use Sonata\AdminBundle\Admin\AbstractAdmin;

/**
* @Sonata\AdminOptions(
* label="Category",
* managerType="orm",
* group="Category",
* showInDashboard=true,
* keepOpen=true,
* onTop=true,
* icon="<i class='fa fa-user'></i>",
* labelTranslatorStrategy="sonata.admin.label.strategy.native",
* labelCatalogue="App",
* pagerType="simple",
* controller=CategoryController::class,
* entity=Category::class,
* adminCode="admin_code",
* autowireEntity=true,
* )
*/
final class CategoryAdmin extends AbstractAdmin
{
}


.. _`here`: https://github.com/kunicmarko20/SonataAutoConfigureBundle#how-does-it-work
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ The demo website can be found at http://demo.sonata-project.org.
cookbook/recipe_creating_an_admin_with_annotations
cookbook/recipe_workflow_integration
cookbook/recipe_sonata_admin_without_user_bundle
cookbook/recipe_auto_configure_admin_classes

0 comments on commit 3ed0f9c

Please sign in to comment.