Explorar el Código

Fix form/filter templates configuration, add LICENSE

Thomas Rabaix hace 13 años
padre
commit
0fca5c6e27

+ 74 - 0
DependencyInjection/Compiler/AddTemplatesCompilerPass.php

@@ -0,0 +1,74 @@
+<?php
+
+/*
+ * This file is part of the Sonata project.
+ *
+ * (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.
+ */
+
+namespace Sonata\DoctrineORMAdminBundle\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\Definition;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/*
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+class AddTemplatesCompilerPass implements CompilerPassInterface
+{
+    /**
+     * {@inheritDoc}
+     */
+    public function process(ContainerBuilder $container)
+    {
+        $settings = $this->fixSettings($container);
+        foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) {
+
+            if (!isset($attributes[0]['manager_type']) || $attributes[0]['manager_type'] != 'orm') {
+                continue;
+            }
+
+
+            $definition = $container->getDefinition($id);
+
+            if (!$definition->hasMethodCall('setFormTheme')) {
+                $definition->addMethodCall('setFormTheme', array($settings['templates']['form']));
+            }
+
+            if (!$definition->hasMethodCall('setFilterTheme')) {
+                $definition->addMethodCall('setFilterTheme', array($settings['templates']['filter']));
+            }
+        }
+    }
+
+    public function fixSettings($container)
+    {
+        $pool = $container->getDefinition('sonata.admin.manager.orm');
+
+        // not very clean but don't know how to do that for now
+        $settings = false;
+        $methods  = $pool->getMethodCalls();
+        foreach ($methods as $pos => $calls) {
+            if ($calls[0] == '__hack_doctrine_orm__') {
+                $settings = $calls[1];
+                break;
+            }
+        }
+
+        if ($settings) {
+            unset($methods[$pos]);
+        }
+
+        $pool->setMethodCalls($methods);
+
+        return $settings;
+    }
+
+}

+ 12 - 0
DependencyInjection/Configuration.php

@@ -35,6 +35,18 @@ class Configuration implements ConfigurationInterface
         $treeBuilder = new TreeBuilder();
         $rootNode = $treeBuilder->root('sonata_doctrine_orm_admin', 'array');
 
+        $rootNode
+            ->children()
+                ->arrayNode('templates')
+                    ->addDefaultsIfNotSet()
+                    ->children()
+                        ->scalarNode('form')->defaultValue(array('SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig'))->cannotBeEmpty()->end()
+                        ->scalarNode('filter')->defaultValue(array('SonataDoctrineORMAdminBundle:Form:filter_admin_fields.html.twig'))->cannotBeEmpty()->end()
+                    ->end()
+                ->end()
+            ->end()
+        ;
+
         return $treeBuilder;
     }
 }

+ 2 - 0
DependencyInjection/SonataDoctrineORMAdminExtension.php

@@ -45,5 +45,7 @@ class SonataDoctrineORMAdminExtension extends Extension
         $processor = new Processor();
         $config = $processor->processConfiguration($configuration, $config);
 
+        $pool = $container->getDefinition('sonata.admin.manager.orm');
+        $pool->addMethodCall('__hack_doctrine_orm__', $config);
     }
 }

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2010-2011 thomas.rabaix@sonata-project.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

+ 12 - 0
Resources/views/Form/filter_admin_fields.html.twig

@@ -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.
+
+#}
+
+{% extends 'SonataAdminBundle:Form:filter_admin_fields.html.twig' %}

+ 1 - 1
Resources/views/Form/form_admin_fields.html.twig

@@ -9,7 +9,7 @@ file that was distributed with this source code.
 
 #}
 
-{% extends 'SonataAdminBundle:Form:form_admin_field.html.twig' %}
+{% extends 'SonataAdminBundle:Form:form_admin_fields.html.twig' %}
 
 
 {# Custom Sonata Admin Extension #}

+ 3 - 0
SonataDoctrineORMAdminBundle.php

@@ -12,12 +12,15 @@ namespace Sonata\DoctrineORMAdminBundle;
 
 use Symfony\Component\HttpKernel\Bundle\Bundle;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
+
 use Sonata\DoctrineORMAdminBundle\DependencyInjection\Compiler\AddGuesserCompilerPass;
+use Sonata\DoctrineORMAdminBundle\DependencyInjection\Compiler\AddTemplatesCompilerPass;
 
 class SonataDoctrineORMAdminBundle extends Bundle
 {
     public function build(ContainerBuilder $container)
     {
         $container->addCompilerPass(new AddGuesserCompilerPass());
+        $container->addCompilerPass(new AddTemplatesCompilerPass());
     }
 }