Skip to content

Commit 963c260

Browse files
committed
feature #447 Add tags to Post (yceruto)
This PR was squashed before being merged into the master branch (closes #447). Discussion ---------- Add tags to Post This implements #44 and it's a complete variant of #192 (On hold since Ago 2016). | Blog Post Index | Post Show | | ---- | --- | | ![tags-index](https://cloud.githubusercontent.com/assets/2028198/22331272/8f0522f8-e398-11e6-8efb-41b8ebb119f4.png) | ![tags-show](https://cloud.githubusercontent.com/assets/2028198/22331381/29aa391a-e399-11e6-9f5a-b09b25a86090.png) | | Post New/Edit | | --- | | ![tagsinput](https://cloud.githubusercontent.com/assets/2028198/22348577/3263128e-e3da-11e6-8b62-25f9720f4275.png) | Also this splits the only one fixture class into three classes (`UserFixtures`, `PostFixtures` and `TagFixtures`): - [x] To prevent mess and complexity. - [x] To avoid post title duplicated (slug issue). - [x] To fix example and explanation of: Sharing objects between fixtures (#192 (comment)). - [x] To add a new example about: Fixture ordering and `DependentFixtureInterface` (dependence between fixtures). Add Translation: - [x] English - [x] Español Updated `blog.sqlite` and `blog_test.sqlite` DBs. --- ### Handling Tags (Bootstrap-tagsinput): There is many options to do that: * Form collection to add new tags? * [`select2`](https://select2.github.io/examples.html) or [`chosen`](https://github.com/harvesthq/chosen) js plugins? * [Bootstrap tagsinput](http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/) js plugin? <-- 👍 * [Tokenfield for Bootstrap](http://sliptree.github.io/bootstrap-tokenfield/) js plugin? ### TODO: - [x] Create TagsInputType to handle the post tags collection (Added DataTransformer example) - [x] Add typeaheadjs option to show tags hint. Commits ------- 46a54dd Add tags to Post
2 parents ebca80b + 46a54dd commit 963c260

28 files changed

+708
-41
lines changed

app/Resources/translations/messages.en.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@
202202
<source>label.published_at</source>
203203
<target>Published at</target>
204204
</trans-unit>
205+
<trans-unit id="label.tags">
206+
<source>label.tags</source>
207+
<target>Tags</target>
208+
</trans-unit>
205209
<trans-unit id="label.actions">
206210
<source>label.actions</source>
207211
<target>Actions</target>

app/Resources/translations/messages.es.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@
206206
<source>label.published_at</source>
207207
<target>Publicado el</target>
208208
</trans-unit>
209+
<trans-unit id="label.tags">
210+
<source>label.tags</source>
211+
<target>Etiquetas</target>
212+
</trans-unit>
209213
<trans-unit id="label.actions">
210214
<source>label.actions</source>
211215
<target>Acciones</target>

app/Resources/translations/validators.en.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<source>post.too_short_content</source>
1515
<target>Post content is too short ({{ limit }} characters minimum)</target>
1616
</trans-unit>
17+
<trans-unit id="post.too_much_tags">
18+
<source>post.too_much_tags</source>
19+
<target>Too much tags ({{ limit }} maximum)</target>
20+
</trans-unit>
1721
<trans-unit id="comment.blank">
1822
<source>comment.blank</source>
1923
<target>Please don't leave your comment blank!</target>

app/Resources/translations/validators.es.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<source>post.too_short_content</source>
1515
<target>El contenido del artículo es demasiado corto ({{ limit }} caracteres como mínimo)</target>
1616
</trans-unit>
17+
<trans-unit id="post.too_much_tags">
18+
<source>post.too_much_tags</source>
19+
<target>Demasiadas etiquetas ({{ limit }} como máximo)</target>
20+
</trans-unit>
1721
<trans-unit id="comment.blank">
1822
<source>comment.blank</source>
1923
<target>No es posible dejar el contenido del comentario vacío.</target>

app/Resources/views/admin/blog/new.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
{{ form_row(form.summary) }}
1111
{{ form_row(form.content) }}
1212
{{ form_row(form.publishedAt) }}
13+
{{ form_row(form.tags) }}
1314

1415
<input type="submit" value="{{ 'label.create_post'|trans }}" class="btn btn-primary" />
1516
{{ form_widget(form.saveAndCreateNew, { label: 'label.save_and_create_new', attr: { class: 'btn btn-primary' } }) }}

app/Resources/views/admin/blog/show.html.twig

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

55
{% block main %}
66
<h1>{{ post.title }}</h1>
7+
78
<p class="post-metadata">
89
<span class="metadata"><i class="fa fa-calendar"></i> {{ post.publishedAt|localizeddate('long', 'medium', null, 'UTC') }}</span>
910
<span class="metadata"><i class="fa fa-user"></i> {{ post.author.email }}</span>
@@ -14,6 +15,8 @@
1415
</div>
1516

1617
{{ post.content|md2html }}
18+
19+
{{ include('blog/_post_tags.html.twig') }}
1720
{% endblock %}
1821

1922
{% block sidebar %}

app/Resources/views/base.html.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<link rel="stylesheet" href="{{ asset('css/font-lato.css') }}">
1717
<link rel="stylesheet" href="{{ asset('css/bootstrap-datetimepicker.min.css') }}">
1818
<link rel="stylesheet" href="{{ asset('css/highlight-solarized-light.css') }}">
19+
<link rel="stylesheet" href="{{ asset('css/bootstrap-tagsinput.css') }}">
1920
<link rel="stylesheet" href="{{ asset('css/main.css') }}">
2021
{% endblock %}
2122
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
@@ -141,6 +142,7 @@
141142
<script src="{{ asset('js/bootstrap-3.3.7.min.js') }}"></script>
142143
<script src="{{ asset('js/highlight.pack.js') }}"></script>
143144
<script src="{{ asset('js/bootstrap-datetimepicker.min.js') }}"></script>
145+
<script src="{{ asset('js/bootstrap-tagsinput.min.js') }}"></script>
144146
<script src="{{ asset('js/main.js') }}"></script>
145147
{% endblock %}
146148

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% if not post.tags.empty %}
2+
<p class="post-tags">
3+
{% for tag in post.tags %}
4+
<span class="label label-success">
5+
<i class="fa fa-tag"></i> {{ tag.name }}
6+
</span>
7+
{% endfor %}
8+
</p>
9+
{% endif %}
10+

app/Resources/views/blog/index.html.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
</a>
1212
</h2>
1313

14+
{{ include('blog/_post_tags.html.twig') }}
15+
1416
<p class="post-metadata">
1517
<span class="metadata"><i class="fa fa-calendar"></i> {{ post.publishedAt|localizeddate('long', 'medium', null, 'UTC') }}</span>
1618
<span class="metadata"><i class="fa fa-user"></i> {{ post.author.email }}</span>

app/Resources/views/blog/index.xml.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<guid>{{ url('blog_post', {'slug': post.slug}) }}</guid>
1717
<pubDate>{{ post.publishedAt|date(format='r', timezone='GMT') }}</pubDate>
1818
<author>{{ post.author.email }}</author>
19+
{% for tag in post.tags %}
20+
<category>{{ tag.name }}</category>
21+
{% endfor %}
1922
</item>
2023
{% endfor %}
2124
</channel>

0 commit comments

Comments
 (0)