Skip to content

Commit

Permalink
improve seo dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Aug 11, 2023
1 parent 9dfd942 commit 0092e6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
13 changes: 12 additions & 1 deletion src/DependencyInjection/Compiler/SchemaGeneratorAdapterPass.php
Expand Up @@ -2,6 +2,7 @@

namespace SchemaBundle\DependencyInjection\Compiler;

use SchemaBundle\EventListener\SchemaListener;
use SchemaBundle\Registry\SchemaGeneratorRegistry;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand All @@ -12,11 +13,15 @@ final class SchemaGeneratorAdapterPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if ($this->hasSeoBundle($container) && $container->hasDefinition(SchemaListener::class)) {
$container->removeDefinition(SchemaListener::class);
}

foreach ($container->findTaggedServiceIds('schema.generator', true) as $id => $tags) {

$definition = $container->getDefinition(SchemaGeneratorRegistry::class);

if ($container->hasParameter('schema.third_party.seo.enabled') && $container->getParameter('schema.third_party.seo.enabled') === true) {
if ($this->hasSeoBundle($container)) {
$message = sprintf(
'Cannot register schema generator "%s" because you have installed the SEO Bundle. If you want to add some fragment generator (via twig) use the "schema.fragment_generator" tag. Read more about it here: %s',
$id,
Expand All @@ -38,4 +43,10 @@ public function process(ContainerBuilder $container): void
}
}
}

private function hasSeoBundle(ContainerBuilder $container): bool
{
/** @phpstan-ignore-next-line */
return $container->hasParameter('schema.third_party.seo.enabled') && $container->getParameter('schema.third_party.seo.enabled') === true;
}
}
9 changes: 2 additions & 7 deletions src/DependencyInjection/SchemaExtension.php
Expand Up @@ -20,20 +20,15 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('services.yaml');
}

public function prepend(ContainerBuilder $container)
public function prepend(ContainerBuilder $container): void
{
if ($container->hasExtension('seo')) {
if (!$container->hasExtension('seo')) {
return;
}

$loader = new YamlFileLoader($container, new FileLocator([__DIR__ . '/../../config']));

$container->setParameter('schema.third_party.seo.enabled', true);

$loader->load('third_party/seo.yaml');

if ($container->hasDefinition(SchemaListener::class)) {
$container->removeDefinition(SchemaListener::class);
}
}
}
5 changes: 0 additions & 5 deletions src/EventListener/SchemaListener.php
Expand Up @@ -32,15 +32,10 @@ public static function getSubscribedEvents(): array
public function onKernelRequest(RequestEvent $event): void
{
$request = $event->getRequest();

if ($event->isMainRequest() === false) {
return;
}

if ($this->pimcoreContextResolver->matchesPimcoreContext($request, PimcoreContextResolver::CONTEXT_ADMIN)) {
return;
}

if (!$this->pimcoreContextResolver->matchesPimcoreContext($request, PimcoreContextResolver::CONTEXT_DEFAULT)) {
return;
}
Expand Down

0 comments on commit 0092e6f

Please sign in to comment.