Skip to content

Commit df2960b

Browse files
committed
minor #448 Tweaked the new blog post tags feature (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #448). Discussion ---------- Tweaked the new blog post tags feature This continues #447 and introduces some minor changes. --- The only relevant changes for end users is the minor redesign of the tags. For example, in the blog index, before tags stand out too much and they look like buttons: ![index-before](https://cloud.githubusercontent.com/assets/73419/22641958/1681671e-ec59-11e6-8178-e60b0eff9a4f.png) Now they are faded because, after all, they are a secondary information: ![index-after](https://cloud.githubusercontent.com/assets/73419/22641977/22e349d2-ec59-11e6-9974-85565c9a565d.png) In the blog post show, the tags are bigger: ![show-after](https://cloud.githubusercontent.com/assets/73419/22641984/2939dc1a-ec59-11e6-952c-fe1d53dc0b04.png) And in the admin, I haven't modified anything, so they still look like this: ![admin-after](https://cloud.githubusercontent.com/assets/73419/22642002/391c0e6e-ec59-11e6-8e8c-f23f7267bc99.png) Commits ------- f09c564 Tweaked the new blog post tags feature
2 parents 963c260 + f09c564 commit df2960b

File tree

13 files changed

+80
-38
lines changed

13 files changed

+80
-38
lines changed

app/Resources/translations/validators.en.xlf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
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>
17+
<trans-unit id="post.too_many_tags">
18+
<source>post.too_many_tags</source>
19+
<target>Too many tags (add {{ limit }} tags or less)</target>
2020
</trans-unit>
2121
<trans-unit id="comment.blank">
2222
<source>comment.blank</source>

app/Resources/translations/validators.es.xlf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
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>
17+
<trans-unit id="post.too_many_tags">
18+
<source>post.too_many_tags</source>
19+
<target>Demasiadas etiquetas (añade {{ limit }} como máximo)</target>
2020
</trans-unit>
2121
<trans-unit id="comment.blank">
2222
<source>comment.blank</source>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% if not post.tags.empty %}
22
<p class="post-tags">
33
{% for tag in post.tags %}
4-
<span class="label label-success">
4+
<span class="label label-default">
55
<i class="fa fa-tag"></i> {{ tag.name }}
66
</span>
77
{% endfor %}

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

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

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

2119
{{ post.summary|md2html }}
20+
21+
{{ include('blog/_post_tags.html.twig') }}
2222
</article>
2323
{% else %}
2424
<div class="well">{{ 'post.no_posts_found'|trans }}</div>

app/config/services.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ services:
2222
tags:
2323
- { name: twig.extension }
2424

25-
# This is only needed if your form type requires some dependencies to be injected
26-
# by the container, otherwise it is unnecessary overhead and therefore not recommended
27-
# to do this for all form type classes.
25+
# Defining a form type as a service is only required when the form type
26+
# needs to use some other services, such as the entity manager.
2827
# See http://symfony.com/doc/current/best_practices/forms.html
2928
app.form.type.tagsinput:
3029
class: AppBundle\Form\Type\TagsInputType

src/AppBundle/DataFixtures/ORM/PostFixtures.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
2222

2323
/**
24-
* Defines the sample data to load in the database when running the unit and
25-
* functional tests.
26-
*
27-
* Execute this command to load the data:
24+
* Defines the sample blog posts to load in the database before running the unit
25+
* and functional tests. Execute this command to load the data.
2826
*
2927
* $ php bin/console doctrine:fixtures:load
3028
*
@@ -53,8 +51,9 @@ public function load(ObjectManager $manager)
5351
$post->setSummary($this->getRandomPostSummary());
5452
$post->setSlug($this->container->get('slugger')->slugify($post->getTitle()));
5553
$post->setContent($this->getPostContent());
56-
// This reference has been added in UserFixtures class and contains
57-
// an instance of User entity.
54+
// "References" are the way to share objects between fixtures defined
55+
// in different files. This reference has been added in the UserFixtures
56+
// file and it contains an instance of the User entity.
5857
$post->setAuthor($this->getReference('anna-admin'));
5958
$post->setPublishedAt(new \DateTime('now - '.$i.'days'));
6059

@@ -79,8 +78,9 @@ public function load(ObjectManager $manager)
7978
}
8079

8180
/**
82-
* This method must return an array of fixtures classes
83-
* on which the implementing class depends on.
81+
* Instead of defining the exact order in which the fixtures files must be loaded,
82+
* this method defines which other fixtures this file depends on. Then, Doctrine
83+
* will figure out the best order to fit all the dependencies.
8484
*
8585
* @return array
8686
*/
@@ -170,14 +170,14 @@ private function getPhrases()
170170
'Eposs sunt solems de superbus fortis',
171171
'Vae humani generis',
172172
'Diatrias tolerare tanquam noster caesium',
173-
'Teres talis orgias saepe tractare de camerarius flavum sensorem',
173+
'Teres talis saepe tractare de camerarius flavum sensorem',
174174
'Silva de secundus galatae demitto quadra',
175175
'Sunt accentores vitare salvus flavum parses',
176-
'Potus sensim ducunt ad ferox abnoba',
176+
'Potus sensim ad ferox abnoba',
177177
'Sunt seculaes transferre talis camerarius fluctuies',
178178
'Era brevis ratione est',
179179
'Sunt torquises imitari velox mirabilis medicinaes',
180-
'Cum mineralis persuadere omnes finises desiderium bi-color',
180+
'Mineralis persuadere omnes finises desiderium',
181181
'Bassus fatalis classiss virtualiter transferre de flavum',
182182
];
183183
}

src/AppBundle/DataFixtures/ORM/TagFixtures.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
use Doctrine\Common\Persistence\ObjectManager;
1717

1818
/**
19-
* Defines the sample data to load in the database when running the unit and
20-
* functional tests.
21-
*
22-
* Execute this command to load the data:
19+
* Defines the sample blog tags to load in the database before running the unit
20+
* and functional tests. Execute this command to load the data.
2321
*
2422
* $ php bin/console doctrine:fixtures:load
2523
*
@@ -30,7 +28,7 @@
3028
class TagFixtures extends AbstractFixture
3129
{
3230
public static $names = [
33-
'Lorem',
31+
'lorem',
3432
'ipsum',
3533
'consectetur',
3634
'adipiscing',

src/AppBundle/DataFixtures/ORM/UserFixtures.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
1919

2020
/**
21-
* Defines the sample data to load in the database when running the unit and
22-
* functional tests.
23-
*
24-
* Execute this command to load the data:
21+
* Defines the sample users to load in the database befre running the unit and
22+
* functional tests. Execute this command to load the data.
2523
*
2624
* $ php bin/console doctrine:fixtures:load
2725
*

src/AppBundle/Entity/Post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Post
105105
*
106106
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Tag", cascade={"persist"})
107107
* @ORM\JoinTable(name="symfony_demo_post_tag")
108-
* @Assert\Count(max="4", maxMessage="post.too_much_tags")
108+
* @Assert\Count(max="4", maxMessage="post.too_many_tags")
109109
*/
110110
private $tags;
111111

tests/AppBundle/Controller/DefaultControllerTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Tests\AppBundle\Controller;
1313

14+
use AppBundle\Entity\Post;
1415
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1516

1617
/**
@@ -43,6 +44,23 @@ public function testPublicUrls($url)
4344
);
4445
}
4546

47+
/**
48+
* A good practice for tests is to not use the service container, to make
49+
* them more robust. However, in this example we must access to the container
50+
* to get the entity manager and make a database query. The reason is that
51+
* blog post fixtures are randomly generated and there's no guarantee that
52+
* a given blog post slug will be available.
53+
*/
54+
public function testPublicBlogPost()
55+
{
56+
// the service container is always available via the client
57+
$client = self::createClient();
58+
$blogPost = $client->getContainer()->get('doctrine')->getRepository(Post::class)->find(1);
59+
$client->request('GET', sprintf('/en/blog/posts/%s', $blogPost->getSlug()));
60+
61+
$this->assertTrue($client->getResponse()->isSuccessful());
62+
}
63+
4664
/**
4765
* The application contains a lot of secure URLs which shouldn't be
4866
* publicly accessible. This tests ensures that whenever a user tries to
@@ -68,7 +86,6 @@ public function getPublicUrls()
6886
{
6987
yield ['/'];
7088
yield ['/en/blog/'];
71-
yield ['/en/blog/posts/morbi-tempus-commodo-mattis'];
7289
yield ['/en/login'];
7390
}
7491

var/data/blog.sqlite

76 KB
Binary file not shown.

var/data/blog_test.sqlite

76 KB
Binary file not shown.

web/css/main.css

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,26 @@ body#login #login-users-help p .console {
224224

225225
/* Page: 'Blog index'
226226
------------------------------------------------------------------------- */
227-
body#blog_index h1 {
227+
body#blog_index h1,
228+
body#blog_index p {
228229
margin-bottom: 0.5em
229230
}
230231

231232
body#blog_index article.post {
232-
margin-bottom: 3em
233+
margin-bottom: 3em;
233234
}
234235

235236
body#blog_index .post-metadata {
236237
font-size: 16px;
237238
margin-bottom: 8px;
238239
}
239240

240-
body#blog_index .post-tags {
241-
margin-bottom: 15px;
241+
body#blog_index .post-tags .label-default {
242+
background-color: #e9ecec;
243+
color: #6d8283;
244+
}
245+
body#blog_index .post-tags .label-default i {
246+
color: #a3b2b2;
242247
}
243248

244249
/* Page: 'Blog post show'
@@ -247,6 +252,17 @@ body#blog_post_show h3 {
247252
margin-bottom: 0.75em
248253
}
249254

255+
body#blog_post_show .post-tags .label-default {
256+
background-color: #e9ecec;
257+
color: #6D8283;
258+
font-size: 16px;
259+
margin-right: 10px;
260+
padding: .4em 1em .5em;
261+
}
262+
body#blog_post_show .post-tags .label-default i {
263+
color: #95A6A7;
264+
}
265+
250266
body#blog_post_show #post-add-comment {
251267
margin: 2em 0
252268
}
@@ -289,6 +305,20 @@ body#admin_post_index .item-actions a.btn + a.btn {
289305
margin-left: 4px
290306
}
291307

308+
/* Page: 'Backend post show'
309+
------------------------------------------------------------------------- */
310+
body#admin_post_show .post-tags .label-default {
311+
background-color: #e9ecec;
312+
color: #6D8283;
313+
font-size: 16px;
314+
margin-right: 10px;
315+
padding: .4em 1em .5em;
316+
}
317+
body#admin_post_show .post-tags .label-default i {
318+
color: #95A6A7;
319+
}
320+
321+
292322
@media (min-width: 768px) and (max-width: 1200px) {
293323
.container {
294324
width: 98%;

0 commit comments

Comments
 (0)