Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-29970: As a Developer I'd like to order components & tabs in Admin UI #783

Merged
merged 3 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/bundle/DependencyInjection/Compiler/ComponentPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,40 @@
use EzSystems\EzPlatformAdminUi\Component\Registry;
use EzSystems\EzPlatformAdminUi\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception;

class ComponentPass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;

const TAG_NAME = 'ezplatform.admin_ui.component';

/**
* @param ContainerBuilder $container
*
* @throws Exception\InvalidArgumentException
* @throws Exception\ServiceNotFoundException
* @throws InvalidArgumentException
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException When a service is abstract
* @throws \EzSystems\EzPlatformAdminUi\Exception\InvalidArgumentException When a tag is missing 'group' attribute
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition(Registry::class)) {
return;
}

$registryDefinition = $container->getDefinition(Registry::class);
$taggedServiceIds = $container->findTaggedServiceIds(self::TAG_NAME);
$services = $this->findAndSortTaggedServices(self::TAG_NAME, $container);

foreach ($services as $serviceReference) {
$id = (string)$serviceReference;
$definition = $container->getDefinition($id);
$tags = $definition->getTag(static::TAG_NAME);

foreach ($taggedServiceIds as $taggedServiceId => $tags) {
foreach ($tags as $tag) {
if (!isset($tag['group'])) {
throw new InvalidArgumentException($taggedServiceId, 'Tag ' . self::TAG_NAME . ' must contain "group" argument.');
throw new InvalidArgumentException($id, 'Tag ' . self::TAG_NAME . ' must contain "group" argument.');
}

$registryDefinition->addMethodCall('addComponent', [$tag['group'], $taggedServiceId, new Reference($taggedServiceId)]);
$registryDefinition->addMethodCall('addComponent', [$tag['group'], $id, $serviceReference]);
}
}
}
Expand Down
29 changes: 19 additions & 10 deletions src/bundle/DependencyInjection/Compiler/TabPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUiBundle\DependencyInjection\Compiler;

use EzSystems\EzPlatformAdminUi\Tab\TabRegistry;
use EzSystems\EzPlatformAdminUi\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* {@inheritdoc}
*/
class TabPass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;

const TAG_TAB = 'ezplatform.tab';

/**
* @param ContainerBuilder $container
*
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException When a service is abstract
* @throws \EzSystems\EzPlatformAdminUi\Exception\InvalidArgumentException When a tag is missing 'group' attribute
*/
public function process(ContainerBuilder $container): void
{
Expand All @@ -28,14 +33,18 @@ public function process(ContainerBuilder $container): void
}

$tabRegistryDefinition = $container->getDefinition(TabRegistry::class);
$tabIds = $container->findTaggedServiceIds(static::TAG_TAB);
$services = $this->findAndSortTaggedServices(static::TAG_TAB, $container);

foreach ($tabIds as $id => $tab) {
$tabDefinition = $container->getDefinition($id);
$tag = $tabDefinition->getTag(static::TAG_TAB);
foreach ($services as $serviceReference) {
$id = (string)$serviceReference;
$definition = $container->getDefinition($id);
$tags = $definition->getTag(static::TAG_TAB);

foreach (array_column($tag, 'group') as $group) {
$tabRegistryDefinition->addMethodCall('addTab', [new Reference($id), $group]);
foreach ($tags as $tag) {
if (!isset($tag['group'])) {
throw new InvalidArgumentException($id, 'Tag ' . self::TAG_NAME . ' must contain "group" argument.');
}
$tabRegistryDefinition->addMethodCall('addTab', [$serviceReference, $tag['group']]);
}
}
}
Expand Down