Skip to content

Commit 55a0c7e

Browse files
committed
Convert partial templates to anonymous Twig components
1 parent b3d8913 commit 55a0c7e

35 files changed

+2511
-1809
lines changed

composer.lock

Lines changed: 200 additions & 194 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"devDependencies": {
33
"@babel/core": "^7.20.5",
4+
"@babel/plugin-proposal-class-properties": "^7.18.6",
45
"@babel/preset-env": "^7.16.0",
56
"@fortawesome/fontawesome-free": "^5.8.1",
67
"@hotwired/stimulus": "^3.0.0",
@@ -36,5 +37,5 @@
3637
"dev": "encore dev",
3738
"watch": "encore dev --watch",
3839
"build": "encore production --progress"
39-
}
40+
}
4041
}

public/build/384.af623ff4.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

public/build/384.dcf0f5e0.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/41.64983f8e.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

public/build/41.64983f8e.js.LICENSE.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

public/build/41.e694ef2e.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*!
2+
* jQuery JavaScript Library v3.7.1
3+
* https://jquery.com/
4+
*
5+
* Copyright OpenJS Foundation and other contributors
6+
* Released under the MIT license
7+
* https://jquery.org/license
8+
*
9+
* Date: 2023-08-28T13:37Z
10+
*/

public/build/630.baecfc2c.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/630.ed629036.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/build/639.295ae6c2.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

public/build/639.5b08c4e9.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/entrypoints.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"entrypoints": {
33
"app": {
44
"js": [
5-
"/build/runtime.5feae901.js",
6-
"/build/41.64983f8e.js",
7-
"/build/639.295ae6c2.js",
5+
"/build/runtime.602271ae.js",
6+
"/build/41.e694ef2e.js",
7+
"/build/639.5b08c4e9.js",
88
"/build/app.22ced1a0.js"
99
],
1010
"css": [
@@ -14,9 +14,9 @@
1414
},
1515
"admin": {
1616
"js": [
17-
"/build/runtime.5feae901.js",
18-
"/build/41.64983f8e.js",
19-
"/build/384.af623ff4.js",
17+
"/build/runtime.602271ae.js",
18+
"/build/41.e694ef2e.js",
19+
"/build/384.dcf0f5e0.js",
2020
"/build/admin.747eb0c9.js"
2121
],
2222
"css": [
@@ -25,13 +25,13 @@
2525
}
2626
},
2727
"integrity": {
28-
"/build/runtime.5feae901.js": "sha384-Dj9HEwBUNZIrIUOJJ4vOrf8e+X7fhJTYGYb0F/RJLrIo5qMTyh/mBApfQI4FmH8F",
29-
"/build/41.64983f8e.js": "sha384-XfOM8D6kvkEmauUMaczMxByKTBpbb9/aDqt1hPMgWDJh1X2ZQu5rIyRn3Ipx+rmn",
30-
"/build/639.295ae6c2.js": "sha384-4mr0Q0pZGcH1xnbq69bTTnnhMQCEAynmxjF0PPEnDngNgQKjPMqqCO2kx7UDIr68",
28+
"/build/runtime.602271ae.js": "sha384-dF31xil8Pd5Q10+H/cMyh0/lXiOpqj9nWyybiEiqLT3R/6EdgarBGBunHt0/JE5k",
29+
"/build/41.e694ef2e.js": "sha384-QxxMokSpl/N5tbqMrdkETeGJgKlXUZlJTEWSm488N3OiEWrKSuQFblZovoC9kZFj",
30+
"/build/639.5b08c4e9.js": "sha384-UITCwTwuCxIV1OWEEPmuXjMDSvpm5YiFsWlxeH+pyRiphuTVJ1HeHivjRdnRbzEv",
3131
"/build/app.22ced1a0.js": "sha384-zlbbpBjMsOQhWbu/y6oSuNjxPtxnQTuH2HP44M2WzqBeAGK7CZadXYlhsXsg3iD8",
3232
"/build/639.76194c5a.css": "sha384-PoA8WLGz/za3OOW7qjoDiv5f8mBVtREO35Z70PFH8PVIdu1+nWVUEetA6Q1o6DhV",
3333
"/build/app.3a149582.css": "sha384-nfrD0DNMpZazGQQAucFPYcE1VsR4Gg5Wut28sAVfEpTl6T5xVyF5D0qoc7GtumrW",
34-
"/build/384.af623ff4.js": "sha384-DTkf7hVvZ08YUepoH5wzP+thJm6maRzLe8KxUgIc2OajdJkoSDct0pJMEPYcEEeF",
34+
"/build/384.dcf0f5e0.js": "sha384-CS4QFyhrteT/K3nsT+8+tKJC/bJMP0gUpzDsZscnhLoLgwwjMbwNbOctBcd8v4N8",
3535
"/build/admin.747eb0c9.js": "sha384-vDe3FhM5HnWbM4nEdbmSv8AB5n/PfPJv0y0Goloka7w6jppc6di5LpKD1A252aFg",
3636
"/build/admin.2b1a6c83.css": "sha384-ikQwASTRPK0sjWtW//EXsUjqkjNxc2Yndtt0m5a/I/qE+qEoikXP5ailZKDaqtN9"
3737
}

public/build/manifest.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"build/app.js": "/build/app.22ced1a0.js",
44
"build/admin.css": "/build/admin.2b1a6c83.css",
55
"build/admin.js": "/build/admin.747eb0c9.js",
6-
"build/runtime.js": "/build/runtime.5feae901.js",
6+
"build/runtime.js": "/build/runtime.602271ae.js",
77
"build/206.b003fa5f.js": "/build/206.b003fa5f.js",
8-
"build/41.64983f8e.js": "/build/41.64983f8e.js",
8+
"build/41.e694ef2e.js": "/build/41.e694ef2e.js",
99
"build/639.76194c5a.css": "/build/639.76194c5a.css",
10-
"build/639.295ae6c2.js": "/build/639.295ae6c2.js",
11-
"build/630.ed629036.js": "/build/630.ed629036.js",
12-
"build/384.af623ff4.js": "/build/384.af623ff4.js",
10+
"build/639.5b08c4e9.js": "/build/639.5b08c4e9.js",
11+
"build/630.baecfc2c.js": "/build/630.baecfc2c.js",
12+
"build/384.dcf0f5e0.js": "/build/384.dcf0f5e0.js",
1313
"build/images/fa-solid-900.svg": "/build/images/fa-solid-900.7a8b4f13.svg",
1414
"build/images/fa-brands-400.svg": "/build/images/fa-brands-400.2f517e09.svg",
1515
"build/fonts/lato-normal-italic.woff": "/build/fonts/lato-normal-italic.62a9c838.woff",

public/build/runtime.5feae901.js renamed to public/build/runtime.602271ae.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Twig/Components/PostComponent.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

templates/admin/blog/edit.html.twig

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
{% block main %}
66
<h1>{{ 'title.edit_post'|trans({'id': post.id}) }}</h1>
77

8-
{{ include('admin/blog/_form.html.twig', {
9-
form: form,
10-
button_label: 'action.save'|trans,
11-
include_back_to_home_link: true,
12-
}, with_context = false) }}
8+
<twig:admin:blog:form :form="form" button_label="{{ 'action.save'|trans }}" include_back_to_home_link="false" />
139
{% endblock %}
1410

1511
{% block sidebar %}
@@ -20,7 +16,7 @@
2016
</div>
2117

2218
<div class="section actions">
23-
{{ include('admin/blog/_delete_form.html.twig', {post: post}, with_context = false) }}
19+
<twig:admin:blog:delete_form :post="post"/>
2420
</div>
2521

2622
{{ parent() }}

templates/admin/blog/show.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
{{ post.content|markdown_to_html|sanitize_html }}
1818

19-
{{ include('blog/_post_tags.html.twig') }}
19+
<twig:blog:post_tags :tags="post.tags"/>
2020
{% endblock %}
2121

2222
{% block sidebar %}
@@ -27,7 +27,7 @@
2727
</div>
2828

2929
<div class="section">
30-
{{ include('admin/blog/_delete_form.html.twig', {post: post}, with_context = false) }}
30+
<twig:admin:blog:delete_form :post="post"/>
3131
</div>
3232

3333
{{ parent() }}

templates/base.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
Symfony Demo
3737
</a>
3838
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#appNavbar" aria-controls="appNavbar" aria-expanded="false" aria-label="Toggle navigation">
39-
<span class="navbar-toggler-icon"></span>
39+
<span class="navbar-toggler-icon"></span>
4040
</button>
4141

4242
<div class="navbar-collapse collapse" id="appNavbar">
@@ -128,7 +128,7 @@
128128
{% block body %}
129129
<div class="row">
130130
<div id="main" class="col-sm-9">
131-
{{ include('default/_flash_messages.html.twig') }}
131+
<twig:flash_messages />
132132

133133
{% block main %}{% endblock %}
134134
</div>
Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1 @@
1-
{#
2-
By default, forms enable client-side validation. This means that you can't
3-
test the server-side validation errors from the browser. To temporarily
4-
disable this validation, add the 'novalidate' attribute:
5-
6-
{{ form_start(form, {method: ..., action: ..., attr: {novalidate: 'novalidate'}}) }}
7-
#}
8-
9-
{{ form_start(form, {method: 'POST', action: path('comment_new', {'postSlug': post.slug})}) }}
10-
{# instead of displaying form fields one by one, you can also display them
11-
all with their default options and styles just by calling to this function:
12-
13-
{{ form_widget(form) }}
14-
#}
15-
16-
<fieldset>
17-
<legend>
18-
<i class="fa fa-comment" aria-hidden="true"></i> {{ 'title.add_comment'|trans }}
19-
</legend>
20-
21-
{# Render any global form error (e.g. when a constraint on a public getter method failed) #}
22-
{{ form_errors(form) }}
23-
24-
<div class="form-group {% if not form.content.vars.valid %}has-error{% endif %}">
25-
{{ form_label(form.content, 'label.content', {label_attr: {class: 'sr-only'}}) }}
26-
27-
{# Render any errors for the "content" field (e.g. when a class property constraint failed) #}
28-
{{ form_errors(form.content) }}
29-
30-
{{ form_widget(form.content, {attr: {rows: 10}}) }}
31-
{{ form_help(form.content) }}
32-
</div>
33-
34-
<div class="form-group">
35-
<button class="btn btn-primary float-right" type="submit">
36-
<i class="fa fa-paper-plane" aria-hidden="true"></i> {{ 'action.publish_comment'|trans }}
37-
</button>
38-
</div>
39-
</fieldset>
40-
{{ form_end(form) }}
1+
<twig:blog:comment_form :form="form" :post="post" />

templates/blog/comment_form_error.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<h1 class="text-danger">{{ 'title.comment_error'|trans }}</h1>
77

88
<div class="jumbotron">
9-
{{ include('blog/_comment_form.html.twig') }}
9+
<twig:blog:comment_form :form="form" :post="post"/>
1010
</div>
1111
{% endblock %}

templates/blog/index.html.twig

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

55
{% block main %}
66
{% for post in paginator.results %}
7-
<twig:post :post="post"/>
7+
<twig:blog:post :post="post"/>
88
{% else %}
99
<div class="jumbotron">{{ 'post.no_posts_found'|trans }}</div>
1010
{% endfor %}
@@ -55,5 +55,5 @@
5555
{{ parent() }}
5656

5757
{{ show_source_code(_self) }}
58-
{{ include('blog/_rss.html.twig') }}
58+
<twig:blog:rss />
5959
{% endblock %}

templates/blog/post_show.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
{{ post.content|markdown_to_html|sanitize_html }}
1414

15-
{{ include('blog/_post_tags.html.twig') }}
15+
<twig:blog:post_tags :tags="post.tags" />
1616

1717
<div id="post-add-comment" class="jumbotron">
1818
{# The 'IS_AUTHENTICATED_FULLY' role ensures that the user has entered
@@ -39,7 +39,7 @@
3939

4040
{% for comment in post.comments %}
4141
<div class="row post-comment">
42-
<a name="comment_{{ comment.id }}"></a>
42+
<a id="comment_{{ comment.id }}"></a>
4343
<h4 class="col-sm-3">
4444
<strong>{{ comment.author.fullName }}</strong> {{ 'post.commented_on'|trans }}
4545
{# it's not mandatory to set the timezone in localizeddate(). This is done to
@@ -73,5 +73,5 @@
7373
{{ parent() }}
7474

7575
{{ show_source_code(_self) }}
76-
{{ include('blog/_rss.html.twig') }}
76+
<twig:blog:rss />
7777
{% endblock %}

templates/admin/blog/_delete_form.html.twig renamed to templates/components/admin/blog/delete_form.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{{ include('blog/_delete_post_confirmation.html.twig') }}
1+
{% props post %}
2+
3+
<twig:modal:delete_post_confirmation/>
24
<form action="{{ url('admin_post_delete', {id: post.id}) }}" method="post" data-confirmation="true" id="delete-form">
35
<input type="hidden" name="token" value="{{ csrf_token('delete') }}" />
46
<button type="submit" class="btn btn-lg btn-block btn-danger">

templates/admin/blog/_form.html.twig renamed to templates/components/admin/blog/form.html.twig

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@
66
{{ form_start(form, {attr: {novalidate: 'novalidate'}}) }}
77
#}
88

9-
{% if show_confirmation|default(false) %}
9+
{% props
10+
form,
11+
show_confirmation = false,
12+
button_label = 'label.create_post'|trans,
13+
include_back_to_home_link = false
14+
%}
15+
16+
{% if show_confirmation %}
1017
{% set attr = {'data-confirmation': 'true'} %}
11-
{{ include('blog/_delete_post_confirmation.html.twig') }}
18+
<twig:modal:delete_post_confirmation/>
1219
{% endif %}
1320

1421
{{ form_start(form, {attr: attr|default({})}) }}
1522
{{ form_widget(form) }}
1623

1724
<button type="submit" class="{{ button_css|default("btn btn-primary") }}">
18-
<i class="fa fa-save" aria-hidden="true"></i> {{ button_label|default('label.create_post'|trans) }}
25+
<i class="fa fa-save" aria-hidden="true"></i> {{ button_label }}
1926
</button>
2027

21-
{% if include_back_to_home_link|default(false) %}
28+
{% if include_back_to_home_link %}
2229
<a href="{{ path('admin_post_index') }}" class="btn btn-link">
2330
<i class="fa fa-list-alt" aria-hidden="true"></i> {{ 'action.back_to_list'|trans }}
2431
</a>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{#
2+
By default, forms enable client-side validation. This means that you can't
3+
test the server-side validation errors from the browser. To temporarily
4+
disable this validation, add the 'novalidate' attribute:
5+
6+
{{ form_start(form, {method: ..., action: ..., attr: {novalidate: 'novalidate'}}) }}
7+
#}
8+
9+
{% props form, post %}
10+
11+
{{ form_start(form, {method: 'POST', action: path('comment_new', {'postSlug': post.slug})}) }}
12+
{# instead of displaying form fields one by one, you can also display them
13+
all with their default options and styles just by calling to this function:
14+
15+
{{ form_widget(form) }}
16+
#}
17+
18+
<fieldset>
19+
<legend>
20+
<i class="fa fa-comment" aria-hidden="true"></i> {{ 'title.add_comment'|trans }}
21+
</legend>
22+
23+
{# Render any global form error (e.g. when a constraint on a public getter method failed) #}
24+
{{ form_errors(form) }}
25+
26+
<div class="form-group {% if not form.content.vars.valid %}has-error{% endif %}">
27+
{{ form_label(form.content, 'label.content', {label_attr: {class: 'sr-only'}}) }}
28+
29+
{# Render any errors for the "content" field (e.g. when a class property constraint failed) #}
30+
{{ form_errors(form.content) }}
31+
32+
{{ form_widget(form.content, {attr: {rows: 10}}) }}
33+
{{ form_help(form.content) }}
34+
</div>
35+
36+
<div class="form-group">
37+
<button class="btn btn-primary float-right" type="submit">
38+
<i class="fa fa-paper-plane" aria-hidden="true"></i> {{ 'action.publish_comment'|trans }}
39+
</button>
40+
</div>
41+
</fieldset>
42+
{{ form_end(form) }}

templates/components/post.html.twig renamed to templates/components/blog/post.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% props post %}
2+
13
<article{{ attributes.defaults({class: 'post'}) }}>
24
<h2>
35
<a href="{{ path('blog_post', {slug: post.slug}) }}">
@@ -12,5 +14,5 @@
1214

1315
<p>{{ post.summary }}</p>
1416

15-
{{ include('blog/_post_tags.html.twig') }}
17+
<twig:blog:post_tags :tags="post.tags" />
1618
</article>

0 commit comments

Comments
 (0)