Skip to content

Commit

Permalink
Sf4 compat & refactor twig path override
Browse files Browse the repository at this point in the history
* Allow Symfony 4
* Overrides Twig path for EasyAdmin namespace with a CompilerPass
  • Loading branch information
alterphp authored Dec 28, 2017
1 parent 42a5377 commit 003fd4c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
56 changes: 28 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,40 @@
"doctrine/doctrine-bundle" : "~1.2",
"doctrine/orm" : "~2.3",
"pagerfanta/pagerfanta" : "~1.0,>=1.0.1",
"sensio/framework-extra-bundle" : "~3.0,>=3.0.2",
"symfony/asset" : "~3.0",
"symfony/config" : "~3.0",
"symfony/dependency-injection" : "~3.0",
"symfony/doctrine-bridge" : "~3.0",
"symfony/event-dispatcher" : "~3.0",
"symfony/form" : "~3.0",
"symfony/framework-bundle" : "~3.0",
"symfony/http-foundation" : "~3.0",
"symfony/http-kernel" : "~3.0",
"symfony/polyfill-mbstring" : "^1.0",
"symfony/property-access" : "~3.0",
"symfony/security-bundle" : "~3.0",
"symfony/translation" : "~3.0",
"symfony/twig-bridge" : "~3.0",
"symfony/twig-bundle" : "~3.0",
"symfony/validator" : "~3.0",
"sensio/framework-extra-bundle" : "~2.3|~3.0,>=3.0.2|4.0.x|~5.0",
"symfony/asset" : "~3.0|^4.0",
"symfony/config" : "~3.0|^4.0",
"symfony/dependency-injection" : "~3.0|^4.0",
"symfony/doctrine-bridge" : "~3.0|^4.0",
"symfony/event-dispatcher" : "~3.0|^4.0",
"symfony/form" : "~3.0|^4.0",
"symfony/framework-bundle" : "~3.0|^4.0",
"symfony/http-foundation" : "~3.0|^4.0",
"symfony/http-kernel" : "~3.0|^4.0",
"symfony/polyfill-mbstring" : "^1.0|^4.0",
"symfony/property-access" : "~3.0|^4.0",
"symfony/security-bundle" : "~3.0|^4.0",
"symfony/translation" : "~3.0|^4.0",
"symfony/twig-bridge" : "~3.0|^4.0",
"symfony/twig-bundle" : "~3.0|^4.0",
"symfony/validator" : "~3.0|^4.0",
"twig/extensions" : "~1.0",
"twig/twig" : "~1.14,>=1.14.2|~2.0",
"twig/twig" : "~1.26|~2.0",
"javiereguiluz/easyadmin-bundle": "^1.16"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle" : "~2.2",
"phpunit/phpunit" : "~5",
"psr/log" : "~1.0",
"symfony/browser-kit" : "~3.0",
"symfony/console" : "~3.0",
"symfony/css-selector" : "~3.0",
"symfony/dom-crawler" : "~3.0",
"symfony/finder" : "~3.0",
"symfony/phpunit-bridge" : "~3.0",
"symfony/templating" : "~3.0",
"symfony/var-dumper" : "~3.0",
"symfony/yaml" : "~3.0"
"symfony/browser-kit" : "~3.0|^4.0",
"symfony/console" : "~3.0|^4.0",
"symfony/css-selector" : "~3.0|^4.0",
"symfony/dom-crawler" : "~3.0|^4.0",
"symfony/finder" : "~3.0|^4.0",
"symfony/phpunit-bridge" : "~3.0|^4.0",
"symfony/templating" : "~3.0|^4.0",
"symfony/var-dumper" : "~3.0|^4.0",
"symfony/yaml" : "~3.0|^4.0"
},
"config": {
"sort-packages": true
Expand All @@ -68,7 +68,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
"dev-master": "1.2.x-dev"
}
}
}
29 changes: 29 additions & 0 deletions src/DependencyInjection/Compiler/TwigPathPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace AlterPHP\EasyAdminExtensionBundle\DependencyInjection\Compiler;

use AlterPHP\EasyAdminExtensionBundle\EasyAdminExtensionBundle;
use EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class TwigPathPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$twigLoaderFilesystemId = $container->getAlias('twig.loader')->__toString();
$twigLoaderFilesystemDefinition = $container->getDefinition($twigLoaderFilesystemId);

// Replaces native EasyAdmin templates
$easyAdminExtensionBundleRefl = new \ReflectionClass(EasyAdminExtensionBundle::class);
$easyAdminExtensionBundlePath = dirname($easyAdminExtensionBundleRefl->getFilename());
$easyAdminExtensionTwigPath = $easyAdminExtensionBundlePath.'/Resources/views';
$twigLoaderFilesystemDefinition->addMethodCall('prependPath', array($easyAdminExtensionTwigPath, 'EasyAdmin'));

$nativeEasyAdminBundleRefl = new \ReflectionClass(EasyAdminBundle::class);
$nativeEasyAdminBundlePath = dirname($nativeEasyAdminBundleRefl->getFilename());
$nativeEasyAdminTwigPath = $nativeEasyAdminBundlePath.'/Resources/views';
// Defines a namespace from native EasyAdmin templates
$twigLoaderFilesystemDefinition->addMethodCall('addPath', array($nativeEasyAdminTwigPath, 'BaseEasyAdmin'));
}
}
8 changes: 3 additions & 5 deletions src/EasyAdminExtensionBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace AlterPHP\EasyAdminExtensionBundle;

use AlterPHP\EasyAdminExtensionBundle\DependencyInjection\Compiler\TwigPathPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand All @@ -11,10 +13,6 @@ public function build(ContainerBuilder $container)
{
parent::build($container);

// Prepend EasyAdminExtension bundle tmeplates to EasyAdmin namespace
$container->prependExtensionConfig(
'twig',
array('paths' => array(__DIR__.'/Resources/views' => 'EasyAdmin'))
);
$container->addCompilerPass(new TwigPathPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
}
}
2 changes: 1 addition & 1 deletion src/Resources/views/default/list.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'EasyAdminBundle:default:list.html.twig' %}
{% extends '@BaseEasyAdmin/default/list.html.twig' %}

{% set requestFilters = app.request.get('filters', {}) %}
{% set _request_parameters = _request_parameters|default({})|merge({
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/form/bootstrap_3_layout.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% use 'EasyAdminBundle:form:bootstrap_3_layout.html.twig' %}
{% use '@BaseEasyAdmin/form/bootstrap_3_layout.html.twig' %}

{% block easyadmin_embedded_list_row %}
{{ render(path('easyadmin', { entity: entity, action: 'embeddedList', filters: filters })) }}
Expand Down

0 comments on commit 003fd4c

Please sign in to comment.