Skip to content

Commit

Permalink
Merge pull request #11 from symfony2admingenerator/symfony4-support
Browse files Browse the repository at this point in the history
Added symfony 4 support
  • Loading branch information
tobias-93 authored Dec 29, 2017
2 parents bc40834 + b151bab commit 634aff4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
composer.lock
composer.phar
vendor
17 changes: 7 additions & 10 deletions DependencyInjection/Compiler/FormCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\HttpKernel\Kernel;

/**
* Processes twig configuration
Expand All @@ -17,23 +18,19 @@ class FormCompilerPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
// Used templates
$templates = ['@AdmingeneratorForm/form_js.html.twig', '@AdmingeneratorForm/form_css.html.twig'];

$resources = $container->getParameter('twig.form.resources');
$alreadyImported = in_array('AdmingeneratorFormBundle::form_js.html.twig', $resources)
&& in_array('AdmingeneratorFormBundle::form_css.html.twig', $resources);
$alreadyImported = count(array_intersect($resources, $templates)) == count($templates);

if (!$alreadyImported) {
// Insert right after form_div_layout.html.twig if exists
if (($key = array_search('form_div_layout.html.twig', $resources)) !== false) {
array_splice($resources, ++$key, 0, array(
'AdmingeneratorFormBundle::form_js.html.twig',
'AdmingeneratorFormBundle::form_css.html.twig'
));
array_splice($resources, ++$key, 0, $templates);
} else {
// Put it in first position
array_unshift($resources, array(
'AdmingeneratorFormBundle::form_js.html.twig',
'AdmingeneratorFormBundle::form_css.html.twig'
));
array_unshift($resources, $templates);
}

$container->setParameter('twig.form.resources', $resources);
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
}
],
"require": {
"symfony/symfony": ">= 2.2.0",
"symfony/config": "~2.2|~3.0|~4.0",
"symfony/dependency-injection": "~2.2|~3.0|~4.0",
"symfony/form": "~2.2|~3.0|~4.0",
"symfony/http-kernel": "~2.2|~3.0|~4.0",
"twig/twig": "~1.26||~2.0",
"twig/extensions": "~1.0"
},
Expand Down

0 comments on commit 634aff4

Please sign in to comment.