Skip to content

Customize template inherited #1672

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/GeneratorTwigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public function getEntityFieldPrintCode($entity, $field): string
return $printCode;
}

public function getHeadPrintCode($title): string
public function getHeadPrintCode($title, $templates_inherited): string
{
if ($this->fileManager->fileExists($this->fileManager->getPathForTemplate('base.html.twig'))) {
return <<<TWIG
{% extends 'base.html.twig' %}
{% extends '$templates_inherited' %}

{% block title %}$title{% endblock %}

Expand Down
17 changes: 17 additions & 0 deletions src/Maker/MakeCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ final class MakeCrud extends AbstractMaker
private Inflector $inflector;
private string $controllerClassName;
private bool $generateTests = false;
private bool $customTemplateAsk = false;
private string $customTemplate = 'base.html.twig';

public function __construct(private DoctrineHelper $doctrineHelper, private FormTypeRenderer $formTypeRenderer)
{
Expand Down Expand Up @@ -100,6 +102,16 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
$defaultControllerClass
);

$customTemplateAsk = $io->confirm('Do you want to inherit a custom template? [Custom]', false);

if ($customTemplateAsk) {
$nameCustomTemplate = $this->customTemplate;
$customTemplate = $io->ask(
sprintf('Enter the location of your custom template (e.g. <fg=yellow>%s</>)', $nameCustomTemplate),
$nameCustomTemplate
);
}

$this->interactSetGenerateTests($input, $io);
}

Expand Down Expand Up @@ -196,6 +208,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$entityClassDetails
);

$customTemplate = $this->customTemplate;
$templates = [
'_delete_form' => [
'route_name' => $routeName,
Expand All @@ -209,6 +222,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'entity_identifier' => $entityDoctrineDetails->getIdentifier(),
'route_name' => $routeName,
'templates_path' => $templatesPath,
'templates_inherited' => $customTemplate,
],
'index' => [
'entity_class_name' => $entityClassDetails->getShortName(),
Expand All @@ -217,11 +231,13 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'entity_identifier' => $entityDoctrineDetails->getIdentifier(),
'entity_fields' => $entityDoctrineDetails->getDisplayFields(),
'route_name' => $routeName,
'templates_inherited' => $customTemplate,
],
'new' => [
'entity_class_name' => $entityClassDetails->getShortName(),
'route_name' => $routeName,
'templates_path' => $templatesPath,
'templates_inherited' => $customTemplate,
],
'show' => [
'entity_class_name' => $entityClassDetails->getShortName(),
Expand All @@ -230,6 +246,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'entity_fields' => $entityDoctrineDetails->getDisplayFields(),
'route_name' => $routeName,
'templates_path' => $templatesPath,
'templates_inherited' => $customTemplate,
],
];

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/controller/twig_template.tpl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?= $helper->getHeadPrintCode("Hello $class_name!"); ?>
<?= $helper->getHeadPrintCode("Hello $class_name!", $templates_inherited); ?>

{% block body %}
<style>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/crud/templates/edit.tpl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?= $helper->getHeadPrintCode('Edit '.$entity_class_name) ?>
<?= $helper->getHeadPrintCode('Edit '.$entity_class_name, $templates_inherited) ?>

{% block body %}
<h1>Edit <?= $entity_class_name ?></h1>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/crud/templates/index.tpl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?= $helper->getHeadPrintCode($entity_class_name.' index'); ?>
<?= $helper->getHeadPrintCode($entity_class_name.' index', $templates_inherited); ?>

{% block body %}
<h1><?= $entity_class_name ?> index</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/crud/templates/new.tpl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?= $helper->getHeadPrintCode('New '.$entity_class_name) ?>
<?= $helper->getHeadPrintCode('New '.$entity_class_name, $templates_inherited) ?>

{% block body %}
<h1>Create new <?= $entity_class_name ?></h1>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/crud/templates/show.tpl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?= $helper->getHeadPrintCode($entity_class_name) ?>
<?= $helper->getHeadPrintCode($entity_class_name, $templates_inherited) ?>

{% block body %}
<h1><?= $entity_class_name ?></h1>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/registration/twig_template.tpl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?= $helper->getHeadPrintCode('Register'); ?>
<?= $helper->getHeadPrintCode('Register', $templates_inherited); ?>

{% block body %}
<?php if ($will_verify_email): ?>
Expand Down