Skip to content

Register Twig namespace for Symfony 7.3+/8.0 compatibility#5

Merged
peldax merged 5 commits intomainfrom
copilot/add-graphpinator-extension
Jan 13, 2026
Merged

Register Twig namespace for Symfony 7.3+/8.0 compatibility#5
peldax merged 5 commits intomainfrom
copilot/add-graphpinator-extension

Conversation

Copy link
Contributor

Copilot AI commented Jan 13, 2026

  • Explore repository structure and understand the issue
  • Create DependencyInjection directory
  • Create GraphpinatorExtension class to register Twig namespace
  • Update GraphpinatorBundle to use the new extension
  • Create tests for GraphpinatorExtension and GraphpinatorBundle
  • Verify path resolution is correct
  • Run code review and address feedback (extension property is inherited from parent Bundle class)
  • Verify implementation follows Symfony best practices
  • Add #[\Override] attributes to all overridden methods
  • Enhance test to verify directory exists
  • All changes minimal and focused on the fix

Summary

Addressed code review feedback:

  • Added #[\Override] attributes to all overridden methods in GraphpinatorExtension (load, prepend, getAlias)
  • Added #[\Override] attributes to all overridden methods in GraphpinatorBundle (getPath, getContainerExtension)
  • Enhanced GraphpinatorExtensionTest to verify the configured path actually exists as a directory

The implementation successfully addresses the Twig namespace registration issue for Symfony 7.3+/8.0.

Original prompt

Problem

After updating Symfony dependencies to version 7.3+/8.0, the bundle throws an error:

There are no registered paths for namespace "Graphpinator".

The Twig templates located in src/Resources/views/ are not being found when using @Graphpinator/ui.html.twig and @Graphpinator/schema.html.twig in the GraphQLController.

Root Cause

In Symfony 7.1+, the behavior of AbstractBundle changed. The framework no longer automatically registers Resources/views as a Twig namespace. Bundle developers must now explicitly register Twig namespaces through a Container Extension.

Solution

Create a GraphpinatorExtension class that implements PrependExtensionInterface to register the Twig namespace for the bundle templates, and update GraphpinatorBundle to use this extension.

Files to Create

File: src/DependencyInjection/GraphpinatorExtension.php

<?php

declare(strict_types = 1);

namespace Graphpinator\Symfony\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;

final class GraphpinatorExtension extends Extension implements PrependExtensionInterface
{
    public function load(array $configs, ContainerBuilder $container): void
    {
        // Load services if needed in future
    }

    public function prepend(ContainerBuilder $container): void
    {
        // Register Twig namespace for bundle templates
        $container->prependExtensionConfig('twig', [
            'paths' => [
                \dirname(__DIR__) . '/Resources/views' => 'Graphpinator',
            ],
        ]);
    }

    public function getAlias(): string
    {
        return 'graphpinator';
    }
}

Files to Update

File: src/GraphpinatorBundle.php

Update the bundle to return the custom extension and define the bundle path:

<?php

declare(strict_types = 1);

namespace Graphpinator\Symfony;

use Graphpinator\Symfony\DependencyInjection\GraphpinatorExtension;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

final class GraphpinatorBundle extends AbstractBundle
{
    public function getPath(): string
    {
        return \dirname(__DIR__);
    }

    public function getContainerExtension(): ?ExtensionInterface
    {
        if (null === $this->extension) {
            $this->extension = new GraphpinatorExtension();
        }

        return $this->extension;
    }
}

Expected Outcome

After these changes:

  • The Twig namespace @Graphpinator will be properly registered
  • Templates in src/Resources/views/ will be accessible via @Graphpinator/ui.html.twig and @Graphpinator/schema.html.twig
  • The bundle will work "out of the box" with Symfony 7.3+ and 8.0
  • No breaking changes for existing users

Testing

Verify that:

  1. The /ui route renders correctly using @Graphpinator/ui.html.twig
  2. The /schema route renders correctly using @Graphpinator/schema.html.twig
  3. No Twig namespace errors occur
  4. The bundle remains compatible with both Symfony 7.3 and 8.0

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Jan 13, 2026
Copilot AI and others added 2 commits January 13, 2026 11:16
…stration

Co-authored-by: peldax <10790033+peldax@users.noreply.github.com>
…space registration

Co-authored-by: peldax <10790033+peldax@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GraphpinatorExtension to register Twig namespaces Register Twig namespace for Symfony 7.3+/8.0 compatibility Jan 13, 2026
Copilot AI requested a review from peldax January 13, 2026 11:25
Co-authored-by: peldax <10790033+peldax@users.noreply.github.com>
Copilot AI requested a review from peldax January 13, 2026 11:32
@peldax peldax marked this pull request as ready for review January 13, 2026 11:33
@peldax peldax merged commit aae10e1 into main Jan 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants