Permalink
Browse files

Allow the manager to be defined in the configuration

  • Loading branch information...
1 parent 4c0038d commit 9f9d07d3eda72dc2f9f3d0c997b455319930e5be @rande rande committed Mar 28, 2013
@@ -15,6 +15,7 @@
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
use Sonata\BlockBundle\Exception\BlockOptionsException;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class BlockContextManager implements BlockContextManagerInterface
{
@@ -53,19 +54,8 @@ public function get($meta, array $settings = array())
}
$optionsResolver = new OptionsResolver();
- $optionsResolver->setDefaults(array(
- 'use_cache' => true,
- 'extra_cache_keys' => array(),
- 'attr' => array(),
- 'template' => false,
- ));
- $optionsResolver->addAllowedTypes(array(
- 'use_cache' => array('bool'),
- 'extra_cache_keys' => array('array'),
- 'attr' => array('array'),
- 'template' => array('string', 'bool'),
- ));
+ $this->setDefaultSettings($optionsResolver, $block);
$service = $this->blockService->get($block);
$service->setDefaultSettings($optionsResolver, $block);
@@ -79,4 +69,27 @@ public function get($meta, array $settings = array())
return new BlockContext($block, $settings);
}
+
+ /**
+ * @param OptionsResolverInterface $optionsResolver
+ * @param BlockInterface $block
+ */
+ protected function setDefaultSettings(OptionsResolverInterface $optionsResolver, BlockInterface $block)
+ {
+ $optionsResolver->setDefaults(array(
+ 'use_cache' => true,
+ 'extra_cache_keys' => array(),
+ 'attr' => array(),
+ 'template' => false,
+ 'ttl' => $block->getTtl(),
+ ));
+
+ $optionsResolver->addAllowedTypes(array(
+ 'use_cache' => array('bool'),
+ 'extra_cache_keys' => array('array'),
+ 'attr' => array('array'),
+ 'ttl' => array('int'),
+ 'template' => array('string', 'bool'),
+ ));
+ }
}
@@ -48,6 +48,8 @@ public function getConfigTreeBuilder()
->prototype('scalar')->end()
->end()
+ ->scalarNode('context_manager')->defaultValue('sonata.block.context_manager.default')->end()
+
->arrayNode('templates')
->addDefaultsIfNotSet()
->children()
@@ -44,6 +44,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('core.xml');
$loader->load('exception.xml');
+ $this->configureContext($container, $config);
$this->configureLoaderChain($container, $config);
$this->configureCache($container, $config);
$this->configureForm($container, $config);
@@ -64,6 +65,15 @@ public function load(array $configs, ContainerBuilder $container)
->replaceArgument(1, $config['templates']);
}
+ /**
+ * @param ContainerBuilder $container
+ * @param array $config
+ */
+ public function configureContext(ContainerBuilder $container, array $config)
+ {
+ $container->setAlias('sonata.block.context_manager', $config['context_manager']);
+ }
+
/**
* @param ContainerBuilder $container
* @param array $config
@@ -11,7 +11,7 @@
<argument type="service" id="logger" on-invalid="ignore" />
</service>
- <service id="sonata.block.context_manager" class="Sonata\BlockBundle\Block\BlockContextManager">
+ <service id="sonata.block.context_manager.default" class="Sonata\BlockBundle\Block\BlockContextManager">
<argument type="service" id="sonata.block.loader.service" />
<argument type="service" id="sonata.block.manager" />
</service>
View
@@ -55,3 +55,8 @@ UPGRADE FROM 2.1 to 2.2
=> sonata_block_render(block, {'use_cache': use_cache, 'extra_cache_key': extra_cache_key})
+
+ If you are using the page bundle you need to configure the ``context_manager`` section
+
+ sonata_block:
+ context_manager: sonata.page.block.context_manager

0 comments on commit 9f9d07d

Please sign in to comment.