Skip to content

Commit

Permalink
register a datetime field type as editable
Browse files Browse the repository at this point in the history
correct documentation

add a time field options in documentation
  • Loading branch information
peter-gribanov committed Jun 16, 2020
1 parent f807ac1 commit 7a52d18
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
44 changes: 42 additions & 2 deletions docs/reference/action_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,56 @@ Available types and associated options
| | catalogue | Translation catalogue. |
+ +---------------------+-----------------------------------------------------------------------+
| | class | Class path for editable association field. |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| currency | currency (m) | A currency string (EUR or USD for instance). |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| date | format | A format understandable by Twig's ``date`` function. |
+ +---------------------+-----------------------------------------------------------------------+
| | timezone | Second argument for Twig's ``date`` function |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| time | format | A format understandable by Twig's ``date`` function. |
+ +---------------------+-----------------------------------------------------------------------+
| | timezone | Second argument for Twig's ``date`` function |
+-----------+---------------------+-----------------------------------------------------------------------+
| datetime | format | A format understandable by Twig's ``date`` function. |
+ +---------------------+-----------------------------------------------------------------------+
| | timezone | Second argument for Twig's ``date`` function |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| time | format | A format understandable by Twig's ``date`` function. |
+ +---------------------+-----------------------------------------------------------------------+
| | timezone | Second argument for Twig's ``date`` function |
+-----------+---------------------+-----------------------------------------------------------------------+
| email | as_string | Renders the email as string, without any link. |
+ +---------------------+-----------------------------------------------------------------------+
| | subject | Add subject parameter to email link. |
+ +---------------------+-----------------------------------------------------------------------+
| | body | Add body parameter to email link. |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| percent | | Renders value as a percentage. |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| string | | Renders a string. |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| text | | See 'string' |
+-----------+---------------------+-----------------------------------------------------------------------+
| html | | Renders string as html |
| textarea | | See 'string' |
+-----------+---------------------+-----------------------------------------------------------------------+
| time | | Renders a datetime's time with format ``H:i:s``. |
| html | | Renders string as html |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| trans | catalogue | Translates the value with catalogue ``catalogue`` if defined. |
+-----------+---------------------+-----------------------------------------------------------------------+
Expand All @@ -215,6 +239,22 @@ Available types and associated options
| | parameters | Route parameters |
+ +---------------------+-----------------------------------------------------------------------+
| | hide_protocol | Hide http:// or https:// (default: false) |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| integer | | Renders a integer. |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+
| smallint | | See 'integer' |
+-----------+---------------------+-----------------------------------------------------------------------+
| bigint | | See 'integer' |
+-----------+---------------------+-----------------------------------------------------------------------+
| bigint | | See 'integer' |
+-----------+---------------------+-----------------------------------------------------------------------+
| decimal | | Renders a decimal. |
+ +---------------------+-----------------------------------------------------------------------+
| | editable | Yes/No; editable allows to edit directly from the list if authorized. |
+-----------+---------------------+-----------------------------------------------------------------------+

If you have the SonataDoctrineORMAdminBundle installed, you have access
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<parameter key="percent">number</parameter>
<parameter key="url">url</parameter>
<parameter key="date">date</parameter>
<parameter key="datetime">datetime</parameter>
</parameter>
</parameters>
<services>
Expand Down
11 changes: 10 additions & 1 deletion src/Resources/views/CRUD/base_list_field.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ file that was distributed with this source code.
) %}

{% if field_description.type == constant('Sonata\\AdminBundle\\Templating\\TemplateRegistry::TYPE_DATE') and value is not empty %}
{% set data_value = value.format('Y-m-d') %}
{# it is a x-editable format https://vitalets.github.io/x-editable/docs.html#date #}
{% set data_value = value|date('Y-m-d') %}
{% elseif field_description.type == constant('Sonata\\AdminBundle\\Templating\\TemplateRegistry::TYPE_DATETIME') and value is not empty %}
{# it is a x-editable format https://vitalets.github.io/x-editable/docs.html#datetime #}
{% set data_value = value|date('Y-m-d H:i') %}
{% elseif field_description.type == constant('Sonata\\AdminBundle\\Templating\\TemplateRegistry::TYPE_BOOLEAN') and value is empty %}
{% set data_value = 0 %}
{% elseif value is iterable %}
Expand All @@ -70,6 +74,11 @@ file that was distributed with this source code.
{% if field_description.label is not same as(false) %}
data-title="{{ field_description.label|trans({}, field_description.translationDomain) }}"
{% endif %}
{% if field_description.type == constant('Sonata\\AdminBundle\\Templating\\TemplateRegistry::TYPE_DATE') %}
data-format="yyyy-mm-dd"
{% elseif field_description.type == constant('Sonata\\AdminBundle\\Templating\\TemplateRegistry::TYPE_DATETIME') %}
data-format="yyyy-mm-dd hh:ii"
{% endif %}
data-pk="{{ admin.id(object) }}"
data-url="{{ url }}" {% endblock %}>
{{ block('field') }}
Expand Down

0 comments on commit 7a52d18

Please sign in to comment.