Skip to content

[TwigComponent] Fix debug command #2088

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

Merged
merged 1 commit into from
Aug 20, 2024
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
2 changes: 1 addition & 1 deletion src/TwigComponent/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ Anonymous Components

.. versionadded:: 2.20

The bundle convention for Anonymous components was added in TwigComponents 2.18.
The bundle convention for Anonymous components was added in TwigComponents 2.20.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm jumping on the occasion... what do you think about something like "The automatic registration of Anonymouns components from Bundle" ?

Just a suggestion, feel free to ignore if you prefer the current one :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simon just saw it, feel free to improve it in a new PR, LGTM 👍


Using a component from a third-party bundle is just as straightforward as using
one from your own application. Once the bundle is installed and configured, you
Expand Down
9 changes: 7 additions & 2 deletions src/TwigComponent/src/Command/TwigComponentDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,14 @@ private function findAnonymousComponents(): array
foreach ($finderTemplates as $template) {
$component = str_replace('/', ':', $template->getRelativePathname());
$component = substr($component, 0, -10); // remove file extension ".html.twig"
$path = $template->getPath();

if (isset($dirs[$template->getPath()]) && FilesystemLoader::MAIN_NAMESPACE !== $dirs[$template->getPath()]) {
$component = $dirs[$template->getPath()].':'.$component;
if ($template->getRelativePath()) {
$path = \rtrim(\substr($template->getPath(), 0, -1 * \strlen($template->getRelativePath())), '/');
}

if (isset($dirs[$path]) && FilesystemLoader::MAIN_NAMESPACE !== $dirs[$path]) {
$component = $dirs[$path].':'.$component;
}

$components[$component] = $component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ public function testWithBundleAnonymousComponent(): void
$this->assertStringContainsString('Anonymous', $display);
}

public function testWithBundleAnonymousComponentSubDir(): void
{
$commandTester = $this->createCommandTester();
$commandTester->execute(['name' => 'Acme:Table:Header']);

$commandTester->assertCommandIsSuccessful();

$display = $commandTester->getDisplay();

$this->tableDisplayCheck($display);
$this->assertStringContainsString('Acme:Table:Header', $display);
$this->assertStringContainsString('@Acme/components/Table/Header.html.twig', $display);
$this->assertStringContainsString('Anonymous', $display);
}

public function testWithoutPublicProps(): void
{
$commandTester = $this->createCommandTester();
Expand Down