Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Allow disabling of content listener.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Glassman committed Feb 19, 2015
1 parent e488e32 commit fb0f53a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 11 deletions.
9 changes: 7 additions & 2 deletions DependencyInjection/CmfSeoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ public function load(array $configs, ContainerBuilder $container)
$this->loadSonataAdmin($config['sonata_admin_extension'], $loader, $container, $sonataBundles);
}

if ($this->isConfigEnabled($container, $config['alternate_locale'])) {
$this->loadAlternateLocaleProvider($config['alternate_locale'], $container);
if ($config['enable_content_listener']) {

$loader->load('content-listener.xml');

if ($this->isConfigEnabled($container, $config['alternate_locale'])) {
$this->loadAlternateLocaleProvider($config['alternate_locale'], $container);
}
}

$errorConfig = isset($config['error']) ? $config['error'] : array();
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function getConfigTreeBuilder()
->scalarNode('enable_sibling_provider')->defaultValue(false)->end()
->end()
->end()
->booleanNode('enable_content_listener')->defaultTrue()->end()
->end()
;

Expand Down
20 changes: 20 additions & 0 deletions Resources/config/content-listener.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>

<container
xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="cmf_seo.event_listener.seo_content.class">Symfony\Cmf\Bundle\SeoBundle\EventListener\ContentListener</parameter>
</parameters>

<services>
<service id="cmf_seo.event_listener.seo_content" class="%cmf_seo.event_listener.seo_content.class%">
<argument type="service" id="cmf_seo.presentation"/>
<argument>%cmf_seo.content_key%</argument>
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest"/>
</service>
</services>

</container>
1 change: 1 addition & 0 deletions Resources/config/schema/seo-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<xsd:attribute name="content-key" type="xsd:string" />
<xsd:attribute name="metadata-listener" type="enable_auto" />
<xsd:attribute name="sonata-admin-extension" type="enable_auto" />
<xsd:attribute name="enable-content-listener" type="xsd:boolean" default="true" />
</xsd:complexType>

<xsd:complexType name="persistence">
Expand Down
9 changes: 0 additions & 9 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@

<parameters>
<parameter key="cmf_seo.config_values.class">Symfony\Cmf\Bundle\SeoBundle\DependencyInjection\ConfigValues</parameter>

<parameter key="cmf_seo.form.type.seo_metadata.class">Symfony\Cmf\Bundle\SeoBundle\Form\Type\SeoMetadataType</parameter>
<parameter key="cmf_seo.cache.file.class">Symfony\Cmf\Bundle\SeoBundle\Cache\FileCache</parameter>
<parameter key="cmf_seo.presentation.class">Symfony\Cmf\Bundle\SeoBundle\SeoPresentation</parameter>
<parameter key="cmf_seo.event_listener.seo_content.class">Symfony\Cmf\Bundle\SeoBundle\EventListener\ContentListener</parameter>
<parameter key="cmf_seo.error.suggestion_provider.controller.class">Symfony\Cmf\Bundle\SeoBundle\Controller\SuggestionProviderController</parameter>

</parameters>

<services>
Expand Down Expand Up @@ -45,12 +42,6 @@
<argument type="service" id="cmf_seo.cache" />
</service>

<service id="cmf_seo.event_listener.seo_content" class="%cmf_seo.event_listener.seo_content.class%">
<argument type="service" id="cmf_seo.presentation"/>
<argument>%cmf_seo.content_key%</argument>
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest"/>
</service>

<service id="cmf_seo.error.suggestion_provider.controller" class="%cmf_seo.error.suggestion_provider.controller.class%">
<argument type="service" id="twig" />
<argument>%kernel.debug%</argument>
Expand Down
21 changes: 21 additions & 0 deletions Tests/Unit/DependencyInjection/CmfSeoExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,25 @@ public function testErrorHandlingPHPCR()
array('group' => 'parent')
);
}

public function testDisableSeoContentListener()
{
$this->container->setParameter(
'kernel.bundles',
array(
'DoctrinePHPCRBundle' => true,
'CmfRoutingBundle' => true,
)
);
$this->load(array(
'persistence' => array(
'phpcr' => true,
),
'enable_content_listener' => false
));

$this->assertContainerBuilderNotHasService(
'cmf_seo.event_listener.seo_content'
);
}
}
1 change: 1 addition & 0 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function testDefaultsForAllConfigFormats()
'enabled' => false,
'provider_id' => null,
),
'enable_content_listener' => true,
);

$sources = array_map(function ($path) {
Expand Down

0 comments on commit fb0f53a

Please sign in to comment.