Skip to content

Commit 2b68dd6

Browse files
committed
add bootstrapcss scaffold
1 parent 8226e18 commit 2b68dd6

File tree

16 files changed

+147
-81
lines changed

16 files changed

+147
-81
lines changed

src/Maker/MakeScaffold.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ private function generateScaffold(string $name, ConsoleStyle $io): void
129129
}
130130
}
131131

132-
$io->text('Copying scaffold files...');
132+
if (is_dir($scaffold['dir'])) {
133+
$io->text('Copying scaffold files...');
133134

134-
(new Filesystem())->mirror($scaffold['dir'], $this->files->getRootDirectory());
135+
(new Filesystem())->mirror($scaffold['dir'], $this->files->getRootDirectory());
136+
}
135137

136138
if (isset($scaffold['configure'])) {
137139
$io->text('Executing configuration...');

src/Resources/scaffolds/6.0/auth/templates/login.html.twig

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,36 @@
33
{% block title %}Log in!{% endblock %}
44

55
{% block body %}
6-
<form method="post">
7-
{% if error %}
8-
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
9-
{% endif %}
6+
<div class="row">
7+
<form class="col-md-6 offset-md-3" method="post">
8+
<h1>Please sign in</h1>
109

11-
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
12-
<label for="inputEmail">Email</label>
13-
<input type="email" value="{{ last_username }}" name="email" id="inputEmail" class="form-control" autocomplete="email" required autofocus>
14-
<label for="inputPassword">Password</label>
15-
<input type="password" name="password" id="inputPassword" class="form-control" autocomplete="current-password" required>
16-
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
17-
<div class="checkbox mb-3">
18-
<label>
19-
<input type="checkbox" checked name="_remember_me"> Remember me
20-
</label>
21-
</div>
10+
{% if error %}
11+
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
12+
{% endif %}
2213

23-
{% if app.request.query.has('target') %}
24-
<input type="hidden" name="_target_path" value="{{ app.request.query.get('target') }}"/>
25-
{% endif %}
14+
<div class="mb-3">
15+
<label for="inputEmail">Email</label>
16+
<input type="email" value="{{ last_username }}" name="email" id="inputEmail" class="form-control" autocomplete="email" required autofocus>
17+
</div>
18+
<div class="mb-3">
19+
<label for="inputPassword">Password</label>
20+
<input type="password" name="password" id="inputPassword" class="form-control" autocomplete="current-password" required>
21+
</div>
22+
<div class="checkbox mb-3">
23+
<label>
24+
<input type="checkbox" checked name="_remember_me"> Remember me
25+
</label>
26+
</div>
27+
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
2628

27-
<button class="btn btn-lg btn-primary" type="submit">
28-
Sign in
29-
</button>
30-
</form>
29+
{% if app.request.query.has('target') %}
30+
<input type="hidden" name="_target_path" value="{{ app.request.query.get('target') }}"/>
31+
{% endif %}
32+
33+
<button class="btn btn-primary" type="submit">
34+
Sign in
35+
</button>
36+
</form>
37+
</div>
3138
{% endblock %}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Symfony\Bundle\MakerBundle\FileManager;
4+
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
5+
6+
return [
7+
'description' => 'Add bootstrap css/js.',
8+
'packages' => [
9+
'twig' => 'all',
10+
'encore' => 'all',
11+
],
12+
'configure' => function(FileManager $files) {
13+
$packageJson = json_decode($files->getFileContents('package.json'), true);
14+
$packageJson['devDependencies']['bootstrap'] = '^5.0.0';
15+
$packageJson['devDependencies']['@popperjs/core'] = '^2.0.0';
16+
$files->dumpFile('package.json', json_encode($packageJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
17+
18+
$twig = new YamlSourceManipulator($files->getFileContents('config/packages/twig.yaml'));
19+
$data = $twig->getData();
20+
$data['twig']['form_themes'] = ['bootstrap_5_layout.html.twig'];
21+
$twig->setData($data);
22+
$files->dumpFile('config/packages/twig.yaml', $twig->getContents());
23+
24+
$files->dumpFile('assets/styles/app.css', "@import \"~bootstrap/dist/css/bootstrap.css\";\n");
25+
26+
$appJs = $files->getFileContents('assets/app.js');
27+
28+
if (str_contains($appJs, "require('bootstrap');")) {
29+
return;
30+
}
31+
32+
$files->dumpFile('assets/app.js', $appJs."require('bootstrap');\n");
33+
},
34+
];

src/Resources/scaffolds/6.0/change-password/templates/user/change_password.html.twig

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
{% block title %}Change Password{% endblock %}
44

55
{% block body %}
6-
<h1>Change Password</h1>
6+
<div class="row">
7+
<div class="col-md-6 offset-md-3">
8+
<h1>Change Password</h1>
79

8-
{{ form_start(changePasswordForm) }}
9-
{{ form_row(changePasswordForm.currentPassword, { label: 'Current Password' }) }}
10-
{{ form_row(changePasswordForm.plainPassword.first, { label: 'New Password' }) }}
11-
{{ form_row(changePasswordForm.plainPassword.second, { label: 'Repeat New Password' }) }}
10+
{{ form_start(changePasswordForm) }}
11+
{{ form_row(changePasswordForm.currentPassword, { label: 'Current Password' }) }}
12+
{{ form_row(changePasswordForm.plainPassword.first, { label: 'New Password' }) }}
13+
{{ form_row(changePasswordForm.plainPassword.second, { label: 'Repeat New Password' }) }}
1214

13-
<button type="submit" class="btn">Change Password</button>
14-
{{ form_end(changePasswordForm) }}
15+
<button type="submit" class="btn btn-primary">Change Password</button>
16+
{{ form_end(changePasswordForm) }}
17+
</div>
18+
</div>
1519
{% endblock %}

src/Resources/scaffolds/6.0/change-password/tests/Functional/User/ChangePasswordTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function can_change_password(): void
3333
->click('Change Password')
3434
->assertSuccessful()
3535
->assertOn('/')
36-
->assertSeeIn('.flash', 'You\'ve successfully changed your password.')
36+
->assertSeeIn('.alert', 'You\'ve successfully changed your password.')
3737
->use(Authentication::assertAuthenticatedAs('[email protected]'))
3838
->visit('/logout')
3939
->visit('/login')

src/Resources/scaffolds/6.0/homepage/templates/index.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
{% for type, messages in app.flashes %}
99
{% for message in messages %}
10-
<div class="flash flash-{{ type }}">
10+
<div class="alert alert-{{ type|replace({ error: 'danger' }) }}">
1111
{{ message }}
1212
</div>
1313
{% endfor %}

src/Resources/scaffolds/6.0/profile/templates/user/profile.html.twig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
{% block title %}Manage Profile{% endblock %}
44

55
{% block body %}
6-
<h1>Manage Profile</h1>
6+
<div class="row">
7+
<div class="col-md-6 offset-md-3">
8+
<h1>Manage Profile</h1>
79

8-
{{ form_start(profileForm) }}
9-
{{ form_row(profileForm.name) }}
10+
{{ form_start(profileForm) }}
11+
{{ form_row(profileForm.name) }}
1012

11-
<button type="submit" class="btn">Save</button>
12-
{{ form_end(profileForm) }}
13+
<button type="submit" class="btn btn-primary">Save</button>
14+
{{ form_end(profileForm) }}
15+
</div>
16+
</div>
1317
{% endblock %}

src/Resources/scaffolds/6.0/profile/tests/Functional/User/ProfileTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function can_update_profile(): void
3232
->click('Save')
3333
->assertOn('/')
3434
->assertSuccessful()
35-
->assertSeeIn('.flash', 'You\'ve successfully updated your profile.')
35+
->assertSeeIn('.alert', 'You\'ve successfully updated your profile.')
3636
;
3737

3838
$this->assertSame('John Smith', $user->getName());

src/Resources/scaffolds/6.0/register/src/Form/User/RegistrationFormType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Entity\User;
66
use Symfony\Component\Form\AbstractType;
7+
use Symfony\Component\Form\Extension\Core\Type\EmailType;
78
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
89
use Symfony\Component\Form\FormBuilderInterface;
910
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -21,7 +22,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
2122
new NotBlank(['message' => 'Name is required']),
2223
],
2324
])
24-
->add('email', null, [
25+
->add('email', EmailType::class, [
2526
'constraints' => [
2627
new NotBlank(['message' => 'Email is required']),
2728
new Email(['message' => 'This is not a valid email address']),

src/Resources/scaffolds/6.0/register/templates/user/register.html.twig

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
{% block title %}Register{% endblock %}
44

55
{% block body %}
6-
<h1>Register</h1>
6+
<div class="row">
7+
<div class="col-md-6 offset-md-3">
8+
<h1>Register</h1>
79

8-
{{ form_start(registrationForm) }}
9-
{{ form_row(registrationForm.name) }}
10-
{{ form_row(registrationForm.email) }}
11-
{{ form_row(registrationForm.plainPassword, {
12-
label: 'Password'
13-
}) }}
10+
{{ form_start(registrationForm) }}
11+
{{ form_row(registrationForm.name) }}
12+
{{ form_row(registrationForm.email) }}
13+
{{ form_row(registrationForm.plainPassword, {
14+
label: 'Password'
15+
}) }}
1416

15-
<button type="submit" class="btn">Register</button>
16-
{{ form_end(registrationForm) }}
17+
<button type="submit" class="btn btn-primary">Register</button>
18+
{{ form_end(registrationForm) }}
19+
</div>
20+
</div>
1721
{% endblock %}

src/Resources/scaffolds/6.0/register/tests/Functional/User/RegisterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function can_register(): void
2828
->fillField('Password', 'password')
2929
->click('Register')
3030
->assertOn('/')
31-
->assertSeeIn('.flash', 'You\'ve successfully registered and are now logged in.')
31+
->assertSeeIn('.alert', 'You\'ve successfully registered and are now logged in.')
3232
->use(Authentication::assertAuthenticatedAs('[email protected]'))
3333
->visit('/logout')
3434
->use(Authentication::assertNotAuthenticated())

src/Resources/scaffolds/6.0/reset-password/templates/reset_password/check_email.html.twig

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
{% block title %}Password Reset Email Sent{% endblock %}
44

55
{% block body %}
6-
<p>
7-
If an account matching your email exists, then an email was just sent that contains a link that you can use to reset your password.
8-
This link will expire in {{ resetToken.expirationMessageKey|trans(resetToken.expirationMessageData, 'ResetPasswordBundle') }}.
9-
</p>
10-
<p>If you don't receive an email please check your spam folder or <a href="{{ path('reset_password_request') }}">try again</a>.</p>
6+
<div class="row">
7+
<div class="col-md-6 offset-md-3">
8+
<h1>Password Reset Email Sent</h1>
9+
<p>
10+
If an account matching your email exists, then an email was just sent that contains a link that you can use to reset your password.
11+
This link will expire in {{ resetToken.expirationMessageKey|trans(resetToken.expirationMessageData, 'ResetPasswordBundle') }}.
12+
</p>
13+
<p>If you don't receive an email please check your spam folder or <a href="{{ path('reset_password_request') }}">try again</a>.</p>
14+
</div>
15+
</div>
1116
{% endblock %}

src/Resources/scaffolds/6.0/reset-password/templates/reset_password/request.html.twig

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@
33
{% block title %}Reset your password{% endblock %}
44

55
{% block body %}
6-
{% for flash_error in app.flashes('reset_password_error') %}
7-
<div class="alert alert-danger" role="alert">{{ flash_error }}</div>
8-
{% endfor %}
9-
<h1>Reset your password</h1>
6+
<div class="row">
7+
<div class="col-md-6 offset-md-3">
8+
<h1>Reset your password</h1>
109

11-
{{ form_start(requestForm) }}
12-
{{ form_row(requestForm.email) }}
13-
<div>
14-
<small>
15-
Enter your email address and we will send you a
16-
link to reset your password.
17-
</small>
18-
</div>
10+
{{ form_start(requestForm) }}
11+
{{ form_row(requestForm.email, { help: 'Enter your email address and we will send you a link to reset your password.' }) }}
1912

20-
<button class="btn btn-primary">Send password reset email</button>
21-
{{ form_end(requestForm) }}
13+
<button class="btn btn-primary">Send password reset email</button>
14+
{{ form_end(requestForm) }}
15+
</div>
16+
</div>
2217
{% endblock %}

src/Resources/scaffolds/6.0/reset-password/templates/reset_password/reset.html.twig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
{% block title %}Reset your password{% endblock %}
44

55
{% block body %}
6-
<h1>Reset your password</h1>
6+
<div class="row">
7+
<div class="col-md-6 offset-md-3">
8+
<h1>Reset your password</h1>
79

8-
{{ form_start(resetForm) }}
9-
{{ form_row(resetForm.plainPassword) }}
10-
<button class="btn btn-primary">Reset password</button>
11-
{{ form_end(resetForm) }}
10+
{{ form_start(resetForm) }}
11+
{{ form_row(resetForm.plainPassword) }}
12+
<button class="btn btn-primary">Reset password</button>
13+
{{ form_end(resetForm) }}
14+
</div>
15+
</div>
1216
{% endblock %}

src/Resources/scaffolds/6.0/reset-password/tests/Functional/ResetPasswordTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function can_reset_password(): void
5757
->fillField('Repeat Password', 'new-password')
5858
->click('Reset password')
5959
->assertOn('/')
60-
->assertSeeIn('.flash', 'Your password was successfully reset, you are now logged in.')
60+
->assertSeeIn('.alert', 'Your password was successfully reset, you are now logged in.')
6161
->use(Authentication::assertAuthenticatedAs('[email protected]'))
6262
->visit('/logout')
6363
->visit('/login')
@@ -118,7 +118,7 @@ public function requests_are_throttled(): void
118118
->fillField('Email', '[email protected]')
119119
->click('Send password reset email')
120120
->assertOn('/')
121-
->assertSeeIn('.flash', 'You have already requested a reset password email. Please check your email or try again soon.')
121+
->assertSeeIn('.alert', 'You have already requested a reset password email. Please check your email or try again soon.')
122122
;
123123

124124
$this->mailer()->assertSentEmailCount(1);
@@ -254,7 +254,7 @@ public function cannot_reset_with_invalid_token(): void
254254
$this->browser()
255255
->visit('/reset-password/reset/invalid-token')
256256
->assertOn('/')
257-
->assertSeeIn('.flash', 'The reset password link is invalid. Please try to reset your password again.')
257+
->assertSeeIn('.alert', 'The reset password link is invalid. Please try to reset your password again.')
258258
;
259259
}
260260

@@ -321,7 +321,7 @@ public function reset_tokens_expire(): void
321321
->visit($this->mailer()->sentEmails()->first()->getHeaders()->get('X-CTA')->getBody())
322322
->assertOn('/')
323323
->assertSuccessful()
324-
->assertSeeIn('.flash', 'The link in your email is expired. Please try to reset your password again.')
324+
->assertSeeIn('.alert', 'The link in your email is expired. Please try to reset your password again.')
325325
;
326326
}
327327

@@ -343,12 +343,12 @@ public function cannot_use_token_after_password_change(): void
343343
->fillField('Repeat Password', 'new-password')
344344
->click('Reset password')
345345
->assertOn('/')
346-
->assertSeeIn('.flash', 'Your password was successfully reset, you are now logged in.')
346+
->assertSeeIn('.alert', 'Your password was successfully reset, you are now logged in.')
347347
->visit('/logout')
348348
->visit($resetUrl)
349349
->assertOn('/')
350350
->assertSuccessful()
351-
->assertSeeIn('.flash', 'The reset password link is invalid. Please try to reset your password again.')
351+
->assertSeeIn('.alert', 'The reset password link is invalid. Please try to reset your password again.')
352352
;
353353
}
354354

tests/Maker/MakeScaffoldTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ protected function getMakerClass(): string
5858

5959
private static function scaffoldProvider(): iterable
6060
{
61+
$excluded = ['bootstrapcss', 'starter-kit'];
62+
6163
foreach (Finder::create()->in(__DIR__.'/../../src/Resources/scaffolds/6.0')->name('*.php')->depth(0) as $file) {
62-
yield $file->getFilenameWithoutExtension();
64+
if (\in_array($name = $file->getFilenameWithoutExtension(), $excluded, true)) {
65+
continue;
66+
}
67+
68+
yield $name;
6369
}
6470
}
6571
}

0 commit comments

Comments
 (0)