Skip to content

Commit

Permalink
Merge 3.x into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Mar 12, 2019
2 parents 2081a99 + 63d463f commit 7a99704
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 51 deletions.
21 changes: 21 additions & 0 deletions src/Resources/views/CRUD/display_date.html.twig
@@ -0,0 +1,21 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{%- spaceless %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{% set options = field_description.options %}
<time datetime="{{ value|date('Y-m-d', 'UTC') }}" title="{{ value|date('Y-m-d', 'UTC') }}">
{{ value|date(options.format|default('F j, Y'), options.timezone|default(null)) }}
</time>
{%- endif -%}
{% endspaceless -%}
21 changes: 21 additions & 0 deletions src/Resources/views/CRUD/display_datetime.html.twig
@@ -0,0 +1,21 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{%- spaceless %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{% set options = field_description.options %}
<time datetime="{{ value|date('c', 'UTC') }}" title="{{ value|date('c', 'UTC') }}">
{{ value|date(options.format|default(null), options.timezone|default(null)) }}
</time>
{%- endif -%}
{% endspaceless -%}
20 changes: 20 additions & 0 deletions src/Resources/views/CRUD/display_time.html.twig
@@ -0,0 +1,20 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{%- spaceless %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
<time datetime="{{ value|date('H:i:sP', 'UTC') }}" title="{{ value|date('H:i:sP', 'UTC') }}">
{{ value|date('H:i:s', field_description.options.timezone|default(null)) }}
</time>
{%- endif -%}
{% endspaceless -%}
10 changes: 2 additions & 8 deletions src/Resources/views/CRUD/list_date.html.twig
Expand Up @@ -11,12 +11,6 @@ file that was distributed with this source code.

{% extends get_admin_template('base_list_field', admin.code) %}

{% block field%}
{%- if value is empty -%}
&nbsp;
{%- elseif field_description.options.format is defined -%}
{{ value|date(field_description.options.format) }}
{%- else -%}
{{ value|date('F j, Y') }}
{%- endif -%}
{% block field %}
{%- include '@SonataAdmin/CRUD/display_date.html.twig' -%}
{% endblock %}
6 changes: 1 addition & 5 deletions src/Resources/views/CRUD/list_datetime.html.twig
Expand Up @@ -12,9 +12,5 @@ file that was distributed with this source code.
{% extends get_admin_template('base_list_field', admin.code) %}

{% block field %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{{ value|date(field_description.options.format|default(null), field_description.options.timezone|default(null)) }}
{%- endif -%}
{%- include '@SonataAdmin/CRUD/display_datetime.html.twig' -%}
{% endblock %}
6 changes: 1 addition & 5 deletions src/Resources/views/CRUD/list_time.html.twig
Expand Up @@ -12,9 +12,5 @@ file that was distributed with this source code.
{% extends get_admin_template('base_list_field', admin.code) %}

{% block field %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{{ value|date('H:i:s', field_description.options.timezone|default(null)) }}
{%- endif -%}
{%- include '@SonataAdmin/CRUD/display_time.html.twig' -%}
{% endblock %}
10 changes: 2 additions & 8 deletions src/Resources/views/CRUD/show_date.html.twig
Expand Up @@ -11,12 +11,6 @@ file that was distributed with this source code.

{% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %}

{% block field%}
{%- if value is empty -%}
&nbsp;
{%- elseif field_description.options.format is defined -%}
{{ value|date(field_description.options.format) }}
{%- else -%}
{{ value|date('F j, Y') }}
{%- endif -%}
{% block field %}
{%- include '@SonataAdmin/CRUD/display_date.html.twig' -%}
{% endblock %}
6 changes: 1 addition & 5 deletions src/Resources/views/CRUD/show_datetime.html.twig
Expand Up @@ -12,9 +12,5 @@ file that was distributed with this source code.
{% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %}

{% block field %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{{ value|date(field_description.options.format|default(null), field_description.options.timezone|default(null)) }}
{%- endif -%}
{%- include '@SonataAdmin/CRUD/display_datetime.html.twig' -%}
{% endblock %}
6 changes: 1 addition & 5 deletions src/Resources/views/CRUD/show_time.html.twig
Expand Up @@ -12,9 +12,5 @@ file that was distributed with this source code.
{% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %}

{% block field %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{{ value|date('H:i:s', field_description.options.timezone|default(null)) }}
{%- endif -%}
{%- include '@SonataAdmin/CRUD/display_time.html.twig' -%}
{% endblock %}
54 changes: 39 additions & 15 deletions tests/Twig/Extension/SonataAdminExtensionTest.php
Expand Up @@ -392,15 +392,19 @@ public function getRenderListElementTests()
],
'datetime field' => [
'<td class="sonata-ba-list-field sonata-ba-list-field-datetime" objectId="12345">
December 24, 2013 10:11
<time datetime="2013-12-24T10:11:12+00:00" title="2013-12-24T10:11:12+00:00">
December 24, 2013 10:11
</time>
</td>',
'datetime',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
[],
],
[
'<td class="sonata-ba-list-field sonata-ba-list-field-datetime" objectId="12345">
December 24, 2013 18:11
<time datetime="2013-12-24T10:11:12+00:00" title="2013-12-24T10:11:12+00:00">
December 24, 2013 18:11
</time>
</td>',
'datetime',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('UTC')),
Expand All @@ -414,7 +418,9 @@ public function getRenderListElementTests()
],
[
'<td class="sonata-ba-list-field sonata-ba-list-field-datetime" objectId="12345">
24.12.2013 10:11:12
<time datetime="2013-12-24T10:11:12+00:00" title="2013-12-24T10:11:12+00:00">
24.12.2013 10:11:12
</time>
</td>',
'datetime',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
Expand All @@ -428,7 +434,9 @@ public function getRenderListElementTests()
],
[
'<td class="sonata-ba-list-field sonata-ba-list-field-datetime" objectId="12345">
24.12.2013 18:11:12
<time datetime="2013-12-24T10:11:12+00:00" title="2013-12-24T10:11:12+00:00">
24.12.2013 18:11:12
</time>
</td>',
'datetime',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('UTC')),
Expand All @@ -441,7 +449,11 @@ public function getRenderListElementTests()
['format' => 'd.m.Y H:i:s', 'timezone' => 'Asia/Hong_Kong'],
],
[
'<td class="sonata-ba-list-field sonata-ba-list-field-date" objectId="12345"> December 24, 2013 </td>',
'<td class="sonata-ba-list-field sonata-ba-list-field-date" objectId="12345">
<time datetime="2013-12-24" title="2013-12-24">
December 24, 2013
</time>
</td>',
'date',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
[],
Expand All @@ -453,7 +465,11 @@ public function getRenderListElementTests()
[],
],
[
'<td class="sonata-ba-list-field sonata-ba-list-field-date" objectId="12345"> 24.12.2013 </td>',
'<td class="sonata-ba-list-field sonata-ba-list-field-date" objectId="12345">
<time datetime="2013-12-24" title="2013-12-24">
24.12.2013
</time>
</td>',
'date',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
['format' => 'd.m.Y'],
Expand All @@ -465,13 +481,21 @@ public function getRenderListElementTests()
['format' => 'd.m.Y'],
],
[
'<td class="sonata-ba-list-field sonata-ba-list-field-time" objectId="12345"> 10:11:12 </td>',
'<td class="sonata-ba-list-field sonata-ba-list-field-time" objectId="12345">
<time datetime="10:11:12+00:00" title="10:11:12+00:00">
10:11:12
</time>
</td>',
'time',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
[],
],
[
'<td class="sonata-ba-list-field sonata-ba-list-field-time" objectId="12345"> 18:11:12 </td>',
'<td class="sonata-ba-list-field sonata-ba-list-field-time" objectId="12345">
<time datetime="10:11:12+00:00" title="10:11:12+00:00">
18:11:12
</time>
</td>',
'time',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('UTC')),
['timezone' => 'Asia/Hong_Kong'],
Expand Down Expand Up @@ -1343,42 +1367,42 @@ public function getRenderViewElementTests()
['<th>Data</th> <td>Example</td>', 'text', 'Example', ['safe' => false]],
['<th>Data</th> <td>Example</td>', 'textarea', 'Example', ['safe' => false]],
[
'<th>Data</th> <td>December 24, 2013 10:11</td>',
'<th>Data</th> <td><time datetime="2013-12-24T10:11:12+00:00" title="2013-12-24T10:11:12+00:00"> December 24, 2013 10:11 </time></td>',
'datetime',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')), [],
],
[
'<th>Data</th> <td>24.12.2013 10:11:12</td>',
'<th>Data</th> <td><time datetime="2013-12-24T10:11:12+00:00" title="2013-12-24T10:11:12+00:00"> 24.12.2013 10:11:12 </time></td>',
'datetime',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
['format' => 'd.m.Y H:i:s'],
],
[
'<th>Data</th> <td>December 24, 2013 18:11</td>',
'<th>Data</th> <td><time datetime="2013-12-24T10:11:12+00:00" title="2013-12-24T10:11:12+00:00"> December 24, 2013 18:11 </time></td>',
'datetime',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('UTC')),
['timezone' => 'Asia/Hong_Kong'],
],
[
'<th>Data</th> <td>December 24, 2013</td>',
'<th>Data</th> <td><time datetime="2013-12-24" title="2013-12-24"> December 24, 2013 </time></td>',
'date',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
[],
],
[
'<th>Data</th> <td>24.12.2013</td>',
'<th>Data</th> <td><time datetime="2013-12-24" title="2013-12-24"> 24.12.2013 </time></td>',
'date',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
['format' => 'd.m.Y'],
],
[
'<th>Data</th> <td>10:11:12</td>',
'<th>Data</th> <td><time datetime="10:11:12+00:00" title="10:11:12+00:00"> 10:11:12 </time></td>',
'time',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
[],
],
[
'<th>Data</th> <td>18:11:12</td>',
'<th>Data</th> <td><time datetime="10:11:12+00:00" title="10:11:12+00:00"> 18:11:12 </time></td>',
'time',
new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('UTC')),
['timezone' => 'Asia/Hong_Kong'],
Expand Down

0 comments on commit 7a99704

Please sign in to comment.