Skip to content

move templates to root template dir #1606

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
Sep 28, 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
33 changes: 30 additions & 3 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function generateClass(string $className, string $templateName, array $va
*
* @internal
*
* @param string $templateName Template name in Resources/skeleton to use
* @param string $templateName Template name in the templates/ dir to use
* @param array $variables Array of variables to pass to the template
* @param bool $isController Set to true if generating a Controller that needs
* access to the TemplateComponentGenerator ("generator") in
Expand Down Expand Up @@ -299,10 +299,14 @@ private function addOperation(string $targetPath, string $templateName, array $v

$templatePath = $templateName;
if (!file_exists($templatePath)) {
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;
$templatePath = \sprintf('%s/templates/%s', \dirname(__DIR__), $templateName);

if (!file_exists($templatePath)) {
throw new \Exception(\sprintf('Cannot find template "%s"', $templateName));
$templatePath = $this->getTemplateFromLegacySkeletonPath($templateName);
}

if (!file_exists($templatePath)) {
throw new \Exception(\sprintf('Cannot find template "%s" in the templates/ dir.', $templateName));
}
}

Expand All @@ -311,4 +315,27 @@ private function addOperation(string $targetPath, string $templateName, array $v
'variables' => $variables,
];
}

/**
* @legacy - Remove when public generate methods become "internal" to MakerBundle in v2
*/
private function getTemplateFromLegacySkeletonPath(string $templateName): string
{
$templatePath = $templateName;
if (!file_exists($templatePath)) {
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;

if (!file_exists($templatePath)) {
throw new \Exception(\sprintf('Cannot find template "%s"', $templateName));
}
}

@trigger_deprecation(
'symfony/maker-bundle',
'1.62.0',
'Storing templates in src/Resources/skeleton is deprecated. Store MakerBundle templates in the "~/templates/" dir instead.',
);

return $templatePath;
}
}
4 changes: 2 additions & 2 deletions src/Maker/MakeTwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen

$generator->generateClass(
$factory->getFullName(),
\sprintf('%s/../Resources/skeleton/twig/%s', __DIR__, $live ? 'LiveComponent.tpl.php' : 'Component.tpl.php'),
\sprintf('%s/templates/twig/%s', \dirname(__DIR__, 2), $live ? 'LiveComponent.tpl.php' : 'Component.tpl.php'),
[
'live' => $live,
]
);
$generator->generateTemplate(
"components/{$templatePath}.html.twig",
\sprintf('%s/../Resources/skeleton/twig/%s', __DIR__, 'component_template.tpl.php')
\sprintf('%s/templates/twig/%s', \dirname(__DIR__, 2), 'component_template.tpl.php')
);

$generator->writeChanges();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading