Message-ID: <542375858.2772.1485850755119.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2771_1119348027.1485850755118" ------=_Part_2771_1119348027.1485850755118 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Importing settings from a bundle

Importing settings from a bundle

=20
=20
=20
=20

The following recipe is valid for any type of settings supported by Symf= ony framework.

Description

Usually, you develop your website using one or several custom bundles as= this is a best practice. However, dealing with core bundle semantic config= uration can be a bit tedious if you maintain it in the main app/confi= g/ezplatform.yml configuration file.

Solution

This recipe will show you how to import configuration from a bundle the = manual way and the implicit way.

The manual way

This is the simplest way of doing and it has the advantage of being expl= icit. The idea is to use the imports statement in your main ezplatform.yml:

app/config/ezplatform.yml
=20
imports:
    # Let's import our template selection rules that reside in our custom b=
undle.
    # MyCustomBundle is the actual bundle name
    - {resource: "@AcmeTestBundle/Resources/config/templates_rules.yml"}
 
ezpublish:
    # ...
=20
templates_rules.yml, placed under Resources/config folder in AcmeTestBun= dle
=20
# Here I need to reproduce the right configuration tree.
# It will be merged with the main one
ezpublish:
    system:
        my_siteaccess:
            ezpage:
                layouts:
                    2ZonesLayout1:
                        name: "2 zones (layout 1)"
                        template: "AcmeTestBundle:zone:2zoneslayout1.html.t=
wig"
   =20
            content_view:
                full:
                    article_test:
                        template: "AcmeTestBundle:full:article_test.html.tw=
ig"
                        match:
                            Id\Location: [144,149]
                    another_test:
                        template: "::another_test.html.twig"
                        match:
                            Id\Content: 142
   =20
            block_view:
                campaign:
                    template: "AcmeTestBundle:block:campaign.html.twig"
                    match:
                        Type: "Campaign"

=20

During the merge process, if the imported configuration files contain en= tries that are already defined in the main configuration file, they= will override them.

Tip

If you want to import configuration for development use only, you can do= so in your ezpublish_dev.yml 

The implicit way

The following example will show you how to implicitly load setti= ngs to configure eZ Platform kernel. Note that this is also valid = for any bundle!

We assume here that you're aware of service container extensi= ons.

Acme/TestBundle/DependencyInjection/AcmeTestExtension
=20
<?php
=20
namespace Acme\TestBundle\DependencyInjection;
=20
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterfa=
ce;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Yaml\Yaml;
=20
/**
 * This is the class that loads and manages your bundle configuration
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles=
/extension.html}
 */
class AcmeTestExtension extends Extension implements PrependExtensionInterf=
ace
{
    // ...
=20
    /**
     * Allow an extension to prepend the extension configurations.
     * Here we will load our template selection rules.

     *
     * @param ContainerBuilder $container
     */
    public function prepend( ContainerBuilder $container )
    {
        // Loading our YAML file containing our template rules
        $configFile =3D __DIR__ . '/../Resources/config/template_rules.yml'=
;
        $config =3D Yaml::parse( file_get_contents( $configFile ) );
        // We explicitly prepend loaded configuration for "ezpublish" names=
pace.
        // So it will be placed under the "ezpublish" configuration key, li=
ke in ezpublish.yml.
        $container->prependExtensionConfig( 'ezpublish', $config );
        $container->addResource( new FileResource( $configFile ) );
    }
}

=20
AcmeTestBundle/Resources/config/template_rules.yml
=20
# We explicitly prepend config for "ezpublish" namespace in service=
 container extension, 
# so no need to repeat it here
system:
    ezdemo_frontend_group:
        ezpage:
            layouts:
                2ZonesLayout1:
                    name: "2 zones (layout 1)"
                    template: "AcmeTestBundle:zone:2zoneslayout1.html.twig"
=20
        content_view:
            full:
                article_test:
                    template: "AcmeTestBundle:full:article_test.html.twig"
                    match:
                        Id\Location: 144
                another_test:
                    template: "::another_test.html.twig"
                    match:
                        Id\Content: 142
=20
        block_view:
            campaign:
                template: "AcmeTestBundle:block:campaign.html.twig"
                match:
                    Type: "Campaign"

=20

Regarding performance

Service container extensions are called only when the container is = being compiled, so there is nothing to worry about regarding performance.

Configuration loaded this way will be overridden by the main ezpla= tform.yml file.

 

 

=20
=20
=20
=20

In this topic:

=20
=20
=20
------=_Part_2771_1119348027.1485850755118--