Skip to content

Commit

Permalink
Remove SonataIntlBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Jan 16, 2020
1 parent 11fcc70 commit 5029d4a
Show file tree
Hide file tree
Showing 23 changed files with 355 additions and 34 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": "^2.12",
"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
3 changes: 3 additions & 0 deletions docs/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,6 @@ Full Configuration Options
global_search:
show_empty_boxes: show
case_sensitive: true
# show localized information
use_intl_templates: false
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
5 changes: 5 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ public function getConfigTreeBuilder()
->info('Translate group label')
->end()

->booleanNode('use_intl_templates')
->defaultFalse()
->info('Whether localized information should be shown, it will replace some default templates')
->end()

->end()
->end();

Expand Down
32 changes: 19 additions & 13 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,9 +86,15 @@ public function load(array $configs, ContainerBuilder $container)
$container->removeDefinition('sonata.admin.lock.extension');
}

$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'] + [
$useIntlTemplates = $config['use_intl_templates'] || isset($bundles['SonataIntlBundle']);

if ($useIntlTemplates) {
$loader->load('twig_intl.xml');
}

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

$defaultTemplates = [
'user_block' => '@SonataAdmin/Core/user_block.html.twig',
'add_block' => '@SonataAdmin/Core/add_block.html.twig',
'layout' => '@SonataAdmin/standard_layout.html.twig',
Expand Down Expand Up @@ -128,7 +125,16 @@ public function load(array $configs, ContainerBuilder $container)
'outer_list_rows_mosaic' => '@SonataAdmin/CRUD/list_outer_rows_mosaic.html.twig',
'outer_list_rows_list' => '@SonataAdmin/CRUD/list_outer_rows_list.html.twig',
'outer_list_rows_tree' => '@SonataAdmin/CRUD/list_outer_rows_tree.html.twig',
]);
];

if ($useIntlTemplates &&
$defaultTemplates['history_revision_timestamp'] === $config['templates']['history_revision_timestamp']) {
$config['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'] + $defaultTemplates);
$container->setParameter('sonata.admin.configuration.admin_services', $config['admin_services']);
$container->setParameter('sonata.admin.configuration.dashboard_groups', $config['dashboard']['groups']);
$container->setParameter('sonata.admin.configuration.dashboard_blocks', $config['dashboard']['blocks']);
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/config/twig_intl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sonata.templates.twig_intl.extension" class="Twig\Extra\Intl\IntlExtension">
<tag name="twig.extension"/>
</service>
</services>
</container>
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 <thomas.rabaix@sonata-project.org>
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, attributes, locale) }}
{%- endif -%}
{% endapply -%}
26 changes: 26 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,26 @@
{#
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.
#}

{%- apply spaceless %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{% set pattern = field_description.options.pattern|default('') %}
{% set calendar = field_description.options.calendar|default('') %}
{% 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(dateType, pattern, timezone, calendar, locale) }}
</time>
{%- endif -%}
{% endapply -%}
27 changes: 27 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,27 @@
{#
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.
#}

{%- apply spaceless %}
{%- if value is empty -%}
&nbsp;
{%- else -%}
{% set pattern = field_description.options.pattern|default('') %}
{% set calendar = field_description.options.calendar|default('') %}
{% 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(dateType, timeType, pattern, timezone, calendar, locale) }}
</time>
{%- endif -%}
{% endapply -%}
22 changes: 22 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,22 @@
{#
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.
#}

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

{{ value | format_number(attributes, 'decimal', type, locale) }}
{%- endif -%}
{% endapply -%}
22 changes: 22 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,22 @@
{#
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.
#}

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

{{ value | format_number(attributes, 'percent', type, 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 <thomas.rabaix@sonata-project.org>
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 <thomas.rabaix@sonata-project.org>
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 <thomas.rabaix@sonata-project.org>
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 <thomas.rabaix@sonata-project.org>
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 <thomas.rabaix@sonata-project.org>
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 <thomas.rabaix@sonata-project.org>
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 <thomas.rabaix@sonata-project.org>
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 %}
Loading

0 comments on commit 5029d4a

Please sign in to comment.