Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

make imagine optional even when using the image form type #45

Merged
merged 1 commit into from

3 participants

@dbu
Collaborator

i noticed that the image form type could be useful even without having imagine. this is a slight bc break on the configuration but i think its worth it.

would update the documentation as well if we merge this

@dbu dbu merged commit 693719e into master
@dbu dbu deleted the make-imagine-optional branch
@lsmith77 lsmith77 commented on the diff
DependencyInjection/DoctrinePHPCRExtension.php
((8 lines not shown))
- : array();
-
- $filters[] = $filter;
- $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.filter', $filter);
- $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.all_filters', $filters);
- $this->loader->load('odm_image.xml');
- }
+ $filter = isset($config['image']['imagine_filter'])
+ ? $config['image']['imagine_filter']
+ : false;
+ $filters = isset($config['image']['extra_filters']) && is_array($config['image']['extra_filters'])
+ ? array_merge(array($filter), $config['image']['extra_filters'])
+ : array();
+ $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.filter', $filter);
+ $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.all_filters', $filters);
+ $this->loader->load('odm_image.xml');
@lsmith77 Owner

you are still loading this always which means you always need LiipImagineBundle due to the liip_imagine.cache.manager dependency in doctrine_phpcr.odm.subscriber.image_cache.

now to solve this we can either check for the availability of the LiipImagineBundle in the extension, check for the liip_imagine.cache.manager in a compiler pass. either way both should lead to removing the doctrine_phpcr.odm.subscriber.image_cache service?

@lsmith77 Owner
diff --git a/DependencyInjection/DoctrinePHPCRExtension.php b/DependencyInjection/DoctrinePHPCRExtension.php
index 21c0b15..16b188e 100644
--- a/DependencyInjection/DoctrinePHPCRExtension.php
+++ b/DependencyInjection/DoctrinePHPCRExtension.php
@@ -261,6 +261,10 @@ class DoctrinePHPCRExtension extends AbstractDoctrineExtension
         $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.filter', $filter);
         $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.all_filters', $filters);
         $this->loader->load('odm_image.xml');
+        $bundles = $container->getParameter('kernel.bundles');
+        if (!isset($bundles['LiipImagineBundle'])) {
+            $container->removeDefinition('doctrine_phpcr.odm.subscriber.image_cache');
+        }

         $documentManagers = array();
         foreach ($config['document_managers'] as $name => $documentManager) {
@lsmith77 Owner

committed this as a quick fix a94e1e9

@dbu Collaborator
dbu added a note

indeed you are right, sorry. i think this can also be the not-so-quick fix. or we could check the $filter variable to only remove if that was intended. then the user gets an error if he sets a filter but does not have imagine. shall i change to that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on the diff
Resources/views/Form/fields.html.twig
@@ -1,6 +1,8 @@
{% block phpcr_odm_image_widget %}
{{ form_widget(form) }}
- {% if form.vars.data %}
- <img src="{{ form.vars.data | imagine_filter( imagine_filter ) }}" alt="" />
- {% endif %}
+ {% block phpcr_odm_image_widget_preview %}
+ {% if form.vars.data and imagine_filter %}
+ <img src="{{ form.vars.data | imagine_filter( imagine_filter ) }}" alt="" />
@stof Collaborator
stof added a note

This does not remove the dependency AFAIK as filters are validated at compile time, not at runtime

@dbu Collaborator
dbu added a note

oh, that would be bad. is there a way to avoid the problem? or do we need to provide different twig files for the two cases?

@stof Collaborator
stof added a note

AFAIK, you need a different template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dbu dbu referenced this pull request in symfony-cmf/MediaBundle
Closed

adding media interfaces and a download controller draft #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 15, 2013
  1. @dbu
This page is out of date. Refresh to see the latest.
View
16 DependencyInjection/Configuration.php
@@ -154,7 +154,7 @@ private function addOdmSection(ArrayNodeDefinition $node)
->fixXmlConfig('document_manager')
->append($this->getOdmDocumentManagersNode())
->append($this->getOdmLocaleNode())
- ->append($this->getOdmImagineNode())
+ ->append($this->getOdmImageNode())
->end()
->end()
;
@@ -247,19 +247,17 @@ private function getOdmCacheDriverNode($name)
return $node;
}
- private function getOdmImagineNode()
+ private function getOdmImageNode()
{
$treeBuilder = new TreeBuilder();
- $node = $treeBuilder->root('imagine');
+ $node = $treeBuilder->root('image');
$node
->children()
- ->scalarNode('enabled')->defaultValue(false)->end()
- ->scalarNode('filter')->defaultValue('image_upload_thumbnail')->end()
- ->arrayNode('extra_filters')
- ->requiresAtLeastOneElement()
- ->prototype('scalar')->end()
- ->end()
+ ->scalarNode('imagine_filter')->end()
+ ->arrayNode('extra_filters')
+ ->requiresAtLeastOneElement()
+ ->prototype('scalar')->end()
->end()
->end()
;
View
20 DependencyInjection/DoctrinePHPCRExtension.php
@@ -252,17 +252,15 @@ private function odmLoad(array $config, ContainerBuilder $container)
$dm->addMethodCall('setLocaleChooserStrategy', array(new Reference('doctrine_phpcr.odm.locale_chooser')));
}
- if (isset($config['imagine']['enabled']) && $config['imagine']['enabled']) {
- $filter = $config['imagine']['filter'];
- $filters = isset($config['imagine']['extra_filters']) && is_array($config['imagine']['extra_filters'])
- ? $config['imagine']['extra_filters']
- : array();
-
- $filters[] = $filter;
- $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.filter', $filter);
- $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.all_filters', $filters);
- $this->loader->load('odm_image.xml');
- }
+ $filter = isset($config['image']['imagine_filter'])
+ ? $config['image']['imagine_filter']
+ : false;
+ $filters = isset($config['image']['extra_filters']) && is_array($config['image']['extra_filters'])
+ ? array_merge(array($filter), $config['image']['extra_filters'])
+ : array();
+ $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.filter', $filter);
+ $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.all_filters', $filters);
+ $this->loader->load('odm_image.xml');
@lsmith77 Owner

you are still loading this always which means you always need LiipImagineBundle due to the liip_imagine.cache.manager dependency in doctrine_phpcr.odm.subscriber.image_cache.

now to solve this we can either check for the availability of the LiipImagineBundle in the extension, check for the liip_imagine.cache.manager in a compiler pass. either way both should lead to removing the doctrine_phpcr.odm.subscriber.image_cache service?

@lsmith77 Owner
diff --git a/DependencyInjection/DoctrinePHPCRExtension.php b/DependencyInjection/DoctrinePHPCRExtension.php
index 21c0b15..16b188e 100644
--- a/DependencyInjection/DoctrinePHPCRExtension.php
+++ b/DependencyInjection/DoctrinePHPCRExtension.php
@@ -261,6 +261,10 @@ class DoctrinePHPCRExtension extends AbstractDoctrineExtension
         $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.filter', $filter);
         $container->setParameter('doctrine_phpcr.odm.subscriber.image_cache.all_filters', $filters);
         $this->loader->load('odm_image.xml');
+        $bundles = $container->getParameter('kernel.bundles');
+        if (!isset($bundles['LiipImagineBundle'])) {
+            $container->removeDefinition('doctrine_phpcr.odm.subscriber.image_cache');
+        }

         $documentManagers = array();
         foreach ($config['document_managers'] as $name => $documentManager) {
@lsmith77 Owner

committed this as a quick fix a94e1e9

@dbu Collaborator
dbu added a note

indeed you are right, sorry. i think this can also be the not-so-quick fix. or we could check the $filter variable to only remove if that was intended. then the user gets an error if he sets a filter but does not have imagine. shall i change to that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
$documentManagers = array();
foreach ($config['document_managers'] as $name => $documentManager) {
View
8 Resources/views/Form/fields.html.twig
@@ -1,6 +1,8 @@
{% block phpcr_odm_image_widget %}
{{ form_widget(form) }}
- {% if form.vars.data %}
- <img src="{{ form.vars.data | imagine_filter( imagine_filter ) }}" alt="" />
- {% endif %}
+ {% block phpcr_odm_image_widget_preview %}
+ {% if form.vars.data and imagine_filter %}
+ <img src="{{ form.vars.data | imagine_filter( imagine_filter ) }}" alt="" />
@stof Collaborator
stof added a note

This does not remove the dependency AFAIK as filters are validated at compile time, not at runtime

@dbu Collaborator
dbu added a note

oh, that would be bad. is there a way to avoid the problem? or do we need to provide different twig files for the two cases?

@stof Collaborator
stof added a note

AFAIK, you need a different template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ {% endif %}
+ {% endblock %}
{% endblock %}
Something went wrong with that request. Please try again.