Skip to content

Commit

Permalink
Remove SonataIntlBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Jan 15, 2020
1 parent 11fcc70 commit 953fc6b
Show file tree
Hide file tree
Showing 20 changed files with 323 additions and 30 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"symfony/twig-bundle": "^3.4.30 || ^4.2",
"symfony/validator": "^3.4.30 || ^4.2",
"twig/extensions": "^1.5",
"twig/twig": "^2.10"
"twig/intl-extra": "^3.0",
"twig/twig": "^2.12"
},
"conflict": {
"doctrine/doctrine-bundle": ">=3",
Expand All @@ -67,7 +68,6 @@
"jms/translation-bundle": "^1.4",
"matthiasnoback/symfony-dependency-injection-test": "^3.1",
"sensio/generator-bundle": "^3.1",
"sonata-project/intl-bundle": "^2.4",
"symfony/browser-kit": "^3.4 || ^4.2",
"symfony/css-selector": "^3.4 || ^4.3",
"symfony/filesystem": "^3.4.30 || ^4.2",
Expand Down
37 changes: 18 additions & 19 deletions src/DependencyInjection/AbstractSonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,28 @@ protected function fixTemplatesConfiguration(
],
];

// let's add some magic, only overwrite template if the SonataIntlBundle is enabled
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['SonataIntlBundle'])) {
$useIntlTemplates = $container->getParameter('sonata.admin.configuration.use_intl_templates');
if ($useIntlTemplates) {
$defaultConfig['templates']['types']['list'] = array_merge($defaultConfig['templates']['types']['list'], [
'date' => '@SonataIntl/CRUD/list_date.html.twig',
'datetime' => '@SonataIntl/CRUD/list_datetime.html.twig',
'smallint' => '@SonataIntl/CRUD/list_decimal.html.twig',
'bigint' => '@SonataIntl/CRUD/list_decimal.html.twig',
'integer' => '@SonataIntl/CRUD/list_decimal.html.twig',
'decimal' => '@SonataIntl/CRUD/list_decimal.html.twig',
'currency' => '@SonataIntl/CRUD/list_currency.html.twig',
'percent' => '@SonataIntl/CRUD/list_percent.html.twig',
'date' => '@SonataAdmin/CRUD/Intl/list_date.html.twig',
'datetime' => '@SonataAdmin/CRUD/Intl/list_datetime.html.twig',
'smallint' => '@SonataAdmin/CRUD/Intl/list_decimal.html.twig',
'bigint' => '@SonataAdmin/CRUD/Intl/list_decimal.html.twig',
'integer' => '@SonataAdmin/CRUD/Intl/list_decimal.html.twig',
'decimal' => '@SonataAdmin/CRUD/Intl/list_decimal.html.twig',
'currency' => '@SonataAdmin/CRUD/Intl/list_currency.html.twig',
'percent' => '@SonataAdmin/CRUD/Intl/list_percent.html.twig',
]);

$defaultConfig['templates']['types']['show'] = array_merge($defaultConfig['templates']['types']['show'], [
'date' => '@SonataIntl/CRUD/show_date.html.twig',
'datetime' => '@SonataIntl/CRUD/show_datetime.html.twig',
'smallint' => '@SonataIntl/CRUD/show_decimal.html.twig',
'bigint' => '@SonataIntl/CRUD/show_decimal.html.twig',
'integer' => '@SonataIntl/CRUD/show_decimal.html.twig',
'decimal' => '@SonataIntl/CRUD/show_decimal.html.twig',
'currency' => '@SonataIntl/CRUD/show_currency.html.twig',
'percent' => '@SonataIntl/CRUD/show_percent.html.twig',
'date' => '@SonataAdmin/CRUD/Intl/show_date.html.twig',
'datetime' => '@SonataAdmin/CRUD/Intl/show_datetime.html.twig',
'smallint' => '@SonataAdmin/CRUD/Intl/show_decimal.html.twig',
'bigint' => '@SonataAdmin/CRUD/Intl/show_decimal.html.twig',
'integer' => '@SonataAdmin/CRUD/Intl/show_decimal.html.twig',
'decimal' => '@SonataAdmin/CRUD/Intl/show_decimal.html.twig',
'currency' => '@SonataAdmin/CRUD/Intl/show_currency.html.twig',
'percent' => '@SonataAdmin/CRUD/Intl/show_percent.html.twig',
]);
}

Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ public function getConfigTreeBuilder()
->info('Translate group label')
->end()

->booleanNode('use_intl_templates')
->defaultFalse()
->end()

->end()
->end();

Expand Down
21 changes: 12 additions & 9 deletions src/DependencyInjection/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ public function load(array $configs, ContainerBuilder $container)
]);
}

if (isset($bundles['SonataIntlBundle'])) {
// integrate the SonataUserBundle if the bundle exists
array_unshift($configs, [
'templates' => [
'history_revision_timestamp' => '@SonataIntl/CRUD/history_revision_timestamp.html.twig',
],
]);
}

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('twig.xml');
$loader->load('core.xml');
Expand Down Expand Up @@ -95,6 +86,18 @@ public function load(array $configs, ContainerBuilder $container)
$container->removeDefinition('sonata.admin.lock.extension');
}

$useIntlTemplates = $config['use_intl_templates'] || isset($bundles['SonataIntlBundle']);

$container->setParameter('sonata.admin.configuration.use_intl_templates', $useIntlTemplates);

if ($useIntlTemplates) {
array_unshift($configs, [
'templates' => [
'history_revision_timestamp' => '@SonataAdmin/CRUD/Intl/history_revision_timestamp.html.twig',
],
]);
}

$container->setParameter('sonata.admin.configuration.global_search.empty_boxes', $config['global_search']['empty_boxes']);
$container->setParameter('sonata.admin.configuration.global_search.case_sensitive', $config['global_search']['case_sensitive']);
$container->setParameter('sonata.admin.configuration.templates', $config['templates'] + [
Expand Down
22 changes: 22 additions & 0 deletions src/Resources/views/CRUD/Intl/display_currency.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{%- apply spaceless %}
{%- if value is null -%}
&nbsp;
{%- else -%}
{% set currency = field_description.options.currency %}
{% set attributes = field_description.options.attributes|default({}) %}
{% set locale = field_description.options.locale|default(null) %}

{{ value | format_currency(currency, attrs=attributes locale=locale, attributes) }}
{%- endif -%}
{% endapply -%}
25 changes: 25 additions & 0 deletions src/Resources/views/CRUD/Intl/display_date.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{%- apply spaceless %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{% set pattern = field_description.options.pattern|default(null) %}
{% set locale = field_description.options.locale|default(null) %}
{% set timezone = field_description.options.timezone|default(null) %}
{% set dateType = field_description.options.dateType|default(null) %}

<time datetime="{{ value|date('Y-m-d', 'UTC') }}" title="{{ value|date('Y-m-d', 'UTC') }}">
{{ value|format_date(pattern=pattern, locale=locale, timezone=timezone, dateFormat=dateType) }}
</time>
{%- endif -%}
{% endapply -%}
26 changes: 26 additions & 0 deletions src/Resources/views/CRUD/Intl/display_datetime.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{%- apply spaceless %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{% set pattern = field_description.options.pattern|default(null) %}
{% set locale = field_description.options.locale|default(null) %}
{% set timezone = field_description.options.timezone|default(null) %}
{% set dateType = field_description.options.dateType|default(null) %}
{% set timeType = field_description.options.timeType|default(null) %}

<time datetime="{{ value|date('c', 'UTC') }}" title="{{ value|date('c', 'UTC') }}">
{{ value | format_datetime(pattern=pattern, locale=locale, timezone=timezone, dateFormat=dateType, timeFormat=timeType) }}
</time>
{%- endif -%}
{% endapply -%}
21 changes: 21 additions & 0 deletions src/Resources/views/CRUD/Intl/display_decimal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{%- apply spaceless %}
{%- if value is null -%}
&nbsp;
{%- else -%}
{% set attributes = field_description.options.attributes|default({}) %}
{% set locale = field_description.options.locale|default(null) %}

{{ value | format_number(attributes, style='decimal', locale=locale) }}
{%- endif -%}
{% endapply -%}
21 changes: 21 additions & 0 deletions src/Resources/views/CRUD/Intl/display_percent.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{%- apply spaceless %}
{%- if value is null -%}
&nbsp;
{%- else -%}
{% set attributes = field_description.options.attributes|default({}) %}
{% set locale = field_description.options.locale|default(null) %}

{{ value | format_number(attributes, style='percent', locale=locale) }}
{%- endif -%}
{% endapply -%}
12 changes: 12 additions & 0 deletions src/Resources/views/CRUD/Intl/history_revision_timestamp.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{%- include '@SonataAdmin/CRUD/Intl/display_datetime.html.twig' with { value: revision.timestamp } -%}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_currency.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{% extends admin.getTemplate('base_list_field') %}

{% block field%}
{%- include '@SonataAdmin/CRUD/Intl/display_currency.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_date.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{% extends admin.getTemplate('base_list_field') %}

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_date.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_datetime.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{% extends admin.getTemplate('base_list_field') %}

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_datetime.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_decimal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{% extends admin.getTemplate('base_list_field') %}

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_decimal.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/list_percent.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{% extends admin.getTemplate('base_list_field') %}

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_percent.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/show_currency.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

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

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_currency.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/show_date.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

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

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_date.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/show_datetime.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

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

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_datetime.html.twig' -%}
{% endblock %}
16 changes: 16 additions & 0 deletions src/Resources/views/CRUD/Intl/show_decimal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

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

{% block field %}
{%- include '@SonataAdmin/CRUD/Intl/display_decimal.html.twig' -%}
{% endblock %}
Loading

0 comments on commit 953fc6b

Please sign in to comment.