Skip to content

Commit

Permalink
[AdminBundle] AsMenuAdaptor attribute to easily define menu adaptors …
Browse files Browse the repository at this point in the history
…with custom priorities
  • Loading branch information
acrobat committed Oct 5, 2022
1 parent d666c79 commit 5b39830
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Kunstmaan/AdminBundle/Attribute/AsMenuAdaptor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Kunstmaan\AdminBundle\Attribute;

/**
* Service tag to autoconfigure menu adaptors.
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class AsMenuAdaptor
{
public function __construct(
public int $priority = 0,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Kunstmaan\AdminBundle\DependencyInjection;

use InvalidArgumentException;
use Kunstmaan\AdminBundle\Attribute\AsMenuAdaptor;
use Kunstmaan\AdminBundle\Helper\Menu\MenuAdaptorInterface;
use Kunstmaan\AdminBundle\Service\AuthenticationMailer\SwiftmailerService;
use Kunstmaan\AdminBundle\Service\AuthenticationMailer\SymfonyMailerService;
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\LogicException;
Expand Down Expand Up @@ -74,6 +76,11 @@ public function load(array $configs, ContainerBuilder $container)
$container->registerForAutoconfiguration(MenuAdaptorInterface::class)
->addTag('kunstmaan_admin.menu.adaptor');

$container->registerAttributeForAutoconfiguration(AsMenuAdaptor::class, static function (ChildDefinition $definition, AsMenuAdaptor $attribute, \Reflector $reflector) {
$tagAttributes = get_object_vars($attribute);
$definition->addTag('kunstmaan_admin.menu.adaptor', $tagAttributes);
});

if (!empty($config['enable_console_exception_listener']) && $config['enable_console_exception_listener']) {
$loader->load('console_listener.yml');
}
Expand Down

0 comments on commit 5b39830

Please sign in to comment.