Skip to content

Commit

Permalink
Avoid failing test classes extending from AbstractSonataAdminExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Mar 19, 2020
1 parent 789c660 commit 7788c30
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/DependencyInjection/AbstractSonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ protected function fixTemplatesConfiguration(
],
];

$useIntlTemplates = $container->getParameter('sonata.admin.configuration.use_intl_templates');
$useIntlTemplates = $container->hasParameter('sonata.admin.configuration.use_intl_templates')
? $container->getParameter('sonata.admin.configuration.use_intl_templates')
: false;

if ($useIntlTemplates) {
$defaultConfig['templates']['types']['list'] = array_merge($defaultConfig['templates']['types']['list'], [
Expand Down
13 changes: 2 additions & 11 deletions src/DependencyInjection/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
use JMS\DiExtraBundle\DependencyInjection\Configuration as JMSDiExtraBundleDependencyInjectionConfiguration;
use Sonata\AdminBundle\DependencyInjection\Compiler\ModelManagerCompilerPass;
use Sonata\AdminBundle\Model\ModelManagerInterface;
use Sonata\AdminBundle\Twig\Extension\IntlExtension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -31,7 +29,6 @@
use Symfony\Component\Form\Extension\Core\Type\TextareaType as SymfonyTextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType as SymfonyTextType;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Twig\Extra\Intl\IntlExtension as TwigIntlExtension;

/**
* @final since sonata-project/admin-bundle 3.52
Expand Down Expand Up @@ -94,17 +91,11 @@ public function load(array $configs, ContainerBuilder $container)
$useIntlTemplates = $container->getParameter('sonata.admin.configuration.use_intl_templates');

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

if ('@SonataAdmin/CRUD/history_revision_timestamp.html.twig' === $config['templates']['history_revision_timestamp']) {
$config['templates']['history_revision_timestamp'] = '@SonataAdmin/CRUD/Intl/history_revision_timestamp.html.twig';
}

$twigIntlExtension = new Definition(TwigIntlExtension::class);

$sonataIntlExtension = new Definition(IntlExtension::class);
$sonataIntlExtension->addArgument($twigIntlExtension);
$sonataIntlExtension->addTag('twig.extension');

$container->setDefinition(IntlExtension::class, $sonataIntlExtension);
}

$container->setParameter('sonata.admin.configuration.global_search.empty_boxes', $config['global_search']['empty_boxes']);
Expand Down
11 changes: 11 additions & 0 deletions src/Resources/config/intl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?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="Twig\Extra\Intl\IntlExtension"/>

<service id="Sonata\AdminBundle\Twig\Extension\IntlExtension">
<argument type="service" id="Twig\Extra\Intl\IntlExtension"/>
<tag name="twig.extension"/>
</service>
</services>
</container>
6 changes: 4 additions & 2 deletions src/Twig/Extension/IntlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
*/
final class IntlExtension extends AbstractExtension
{
/**
* @var TwigIntlExtension
*/
private $extension;

public function __construct(TwigIntlExtension $extension)
{
$this->extension = $extension;
}

public function getFilters()
public function getFilters(): array
{
return [
// localized formatters
new TwigFilter('sonata_format_currency', [$this, 'formatCurrency']),
new TwigFilter('sonata_format_number', [$this, 'formatNumber']),
new TwigFilter('sonata_format_datetime', [$this, 'formatDateTime'], ['needs_environment' => true]),
Expand Down

0 comments on commit 7788c30

Please sign in to comment.