hasDefinition('chill.main.menu_composer')) { throw new LogicException(sprintf('The service %s does not exists in ' . 'container.', MenuComposer::class)); } $menuComposerDefinition = $container->getDefinition('chill.main.menu_composer'); $services = []; foreach ($container->findTaggedServiceIds('chill.menu_builder') as $id => $tags) { $services[] = [ 'id' => $id, 'priority' => $tags[0]['priority'] ?? 100, ]; } usort($services, static fn ($a, $b) => $a['priority'] <=> $b['priority']); foreach ($services as $service) { $class = $container->getDefinition($service['id'])->getClass(); foreach ($class::getMenuIds() as $menuId) { $menuComposerDefinition ->addMethodCall('addLocalMenuBuilder', [new Reference($service['id']), $menuId]); } } } }