draw/sonata-extra-bundle

Installs: 5 247

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle


README

This bundle adds some functionalities to the Sonata Project different bundle.

Detect admin argument

The current way to define admin argument is that way:

App\Sonata\Admin\UserAdmin:
    arguments: [ ~, 'App\Entity\User', ~ ]

You can now omit the constructor argument by setting default value in your constructor class:

namespace App\Sonata\Admin;

user App\Entity\User;
use Sonata\AdminBundle\Admin\AbstractAdmin;

class UserAdmin extends AbstractAdmin
{
    public function __construct($code, $class = User::class, $baseControllerName = null)
    {
        parent::__construct($code, $class, $baseControllerName);
    }
}

A compiler will extract the default value from the argument. They need to have the exact same name to be extracted. If you have defined the arguments from any other mean prior to the compiler pass they will not be replaced.

TagSonataAdmin

Base on the terminal42/service-annotation-bundle a custom Draw\Bundle\SonataExtraBundle\Annotation\TagSonataAdmin annotation is available. This bundle need to be installed for the annotation to work.

The tag define the option available at this time in the sonata admin tag. It's not strict so if you define any extra option it will not throw any exception and will pass them through. This allows to support new option without breaking anything but will also not validate any option.

You can now go from:

App\Sonata\Admin\UserAdmin:
    tags:
        - { name: 'sonata.admin', manager_type: 'orm', group: 'User', pager_type: 'simple', icon: 'fas fa-user' }

To:

App\Sonata\Admin\UserAdmin: ~
namespace App\Sonata\Admin;

user App\Entity\User;
use Draw\Bundle\SonataExtraBundle\Annotation\TagSonataAdmin;
use Sonata\AdminBundle\Admin\AbstractAdmin;

/**
 * @TagSonataAdmin(group="User", pager_type="simple", icon="fas fa-user")
 */
class UserAdmin extends AbstractAdmin
{
    public function __construct($code, $class = User::class, $baseControllerName = null)
    {
        parent::__construct($code, $class, $baseControllerName);
    }
}

Fix menu depth when only 1 sub menu

When a menu just have one submenu it can be fix to remove the submenu.

This:

User
 --> List
Entity
 --> List
Section
 --> Entity1 List
 --> Entity2 List

Would become:

User
Entity
Section
 --> Entity1 List
 --> Entity2 List

Enable this feature in config:

draw_sonata_extra:
  fix_menu_depth: true