All Projects → kunicmarko20 → SonataAutoConfigureBundle

kunicmarko20 / SonataAutoConfigureBundle

Licence: MIT License
Symfony Bundle that auto configures Sonata Admin.

Programming Languages

PHP
23972 projects - #3 most used programming language
Gherkin
971 projects
Makefile
30231 projects
shell
77523 projects

Projects that are alternatives of or similar to SonataAutoConfigureBundle

retidy
Extract, unminify, and beautify ("retidy") each file from a webpack/parcel bundle (JavaScript reverse engineering)
Stars: ✭ 27 (+68.75%)
Mutual labels:  bundle
bem-sdk
BEM SDK packages
Stars: ✭ 83 (+418.75%)
Mutual labels:  bundle
BeelabUserBundle
👥 Simple user management for Symfony.
Stars: ✭ 17 (+6.25%)
Mutual labels:  bundle
ExpandedCollectionBundle
Symfony bundle for render entity collections as a selectable expanded list.
Stars: ✭ 13 (-18.75%)
Mutual labels:  bundle
mpx-es-check
Checks the version of ES in JavaScript files with simple shell commands
Stars: ✭ 15 (-6.25%)
Mutual labels:  bundle
AutoFormBundle
Automate Symfony form building
Stars: ✭ 68 (+325%)
Mutual labels:  bundle
KtwDatabaseMenuBundle
Symfony bundle for extending KnpMenu to store menu items in a database.
Stars: ✭ 12 (-25%)
Mutual labels:  bundle
bundle-inspector-webpack-plugin
Bundle Inspector | Analysis Tool for Webpack
Stars: ✭ 19 (+18.75%)
Mutual labels:  bundle
LiipMultiplexBundle
[DEPRECATED] Symfony2 controller that allows calling multiple URL's in one request as well as JSON-ifying any controller
Stars: ✭ 12 (-25%)
Mutual labels:  bundle
easybundler
A code generator for Android Bundles
Stars: ✭ 53 (+231.25%)
Mutual labels:  bundle
BaseBundle
Base for your Symfony bundles.
Stars: ✭ 28 (+75%)
Mutual labels:  bundle
ParamConverterBundle
This bundle provides additional param converters for Symfony.
Stars: ✭ 16 (+0%)
Mutual labels:  bundle
LibBundle
Library and programs for bundle.bin in Content.ggpk of PathOfExile
Stars: ✭ 26 (+62.5%)
Mutual labels:  bundle
SonataAdminSearchBundle
[Abandoned] Implement Search Engine (ElasticSearch) inside Sonata Admin
Stars: ✭ 19 (+18.75%)
Mutual labels:  bundle
TableBundle
Symfony Bundle for easy pagination and filtering
Stars: ✭ 24 (+50%)
Mutual labels:  bundle
VreshTwilioBundle
A Symfony2 wrapper for the official SDK provided by Twilio.
Stars: ✭ 45 (+181.25%)
Mutual labels:  bundle
react-native-ci-tools
Change application bundle name and ID on the fly (build time) for both Android and IOS
Stars: ✭ 30 (+87.5%)
Mutual labels:  bundle
acl-bundle
Integrates the ACL Security component into Symfony applications.
Stars: ✭ 91 (+468.75%)
Mutual labels:  bundle
SonataAnnotationBundle
Annotations for Sonata Admin
Stars: ✭ 23 (+43.75%)
Mutual labels:  sonata-admin
SonataTranslationBundle
SonataTranslationBundle
Stars: ✭ 72 (+350%)
Mutual labels:  bundle

SonataAutoConfigureBundle

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

PHP Version Latest Stable Version Latest Unstable Version

Build Status Coverage Status

Documentation

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

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 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

AdminOptions

<?php

namespace App\Admin;

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

/**
 * @Sonata\AdminOptions(
 *     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
{
}

AdminExtensionOptions

<?php

namespace App\Admin;

use KunicMarko\SonataAutoConfigureBundle\Annotation as Sonata;
use Sonata\AdminBundle\Admin\AbstractAdminExtension;

/**
 * @Sonata\AdminExtensionOptions(
 *     global=true
 * )
 */
final class GlobalExtension extends AbstractAdminExtension
{
}
<?php

namespace App\Admin;

use KunicMarko\SonataAutoConfigureBundle\Annotation as Sonata;
use Sonata\AdminBundle\Admin\AbstractAdminExtension;
use App\Admin\ActivityAdmin;

/**
 * @Sonata\AdminExtensionOptions(
 *     target={"app.admin.project", ActivityAdmin::class}
 * )
 */
final class SortableExtension extends AbstractAdminExtension
{
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].