WARNING: You are browsing the documentation for version 1.0 which is not maintained anymore. If some of your projects are still using this version, consider upgrading.

Persistence

1.0 version
Maintained Unmaintained

Persistence

The CoreBundle lets you to centrally configure the persistence layer for all CMF bundles.

To make the PHPCR-ODM the default persistence layer for all CMF bundles add the following to your main configuration file:

  • YAML
    1
    2
    3
    cmf_core:
        persistence:
            phpcr: ~
    
  • XML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    <?xml version="1.0" charset="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services">
    
        <config xmlns="http://cmf.symfony.com/schema/dic/core">
            <persistence>
                <phpcr />
            </persistence>
        </config>
    
    </container>
    
  • PHP
    1
    2
    3
    4
    5
    $container->loadFromExtension('cmf_core', array(
        'persistence' => array(
            'phpcr' => array(),
        ),
    ));
    

Persisting Documents in Different Languages

Refer to the PHPCR-ODM documentation for details on persisting documents in different languages.

Choosing a Global Translation Strategy

PHPCR-ODM supports multiple different strategies for persisting translations in the repository. When combining Bundles its possible that one ends up with a mix of different strategies which can make providing a generic search across this data more complicated and might also be less efficient depending on the number of different languages used in the system.

For this purpose the CoreBundle provides a Doctrine listener that can optionally enforce a single translation strategy for all documents:

  • YAML
    1
    2
    3
    4
    cmf_core:
        persistence:
            phpcr:
                translation_strategy:  attribute
    
  • XML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    <?xml version="1.0" charset="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services">
    
        <config xmlns="http://cmf.symfony.com/schema/dic/core">
            <persistence>
                <phpcr
                    translation-strategy="attribute"
                />
            </persistence>
        </config>
    
    </container>
    
  • PHP
    1
    2
    3
    4
    5
    6
    7
    $container->loadFromExtension('cmf_core', array(
        'persistence' => array(
            'phpcr' => array(
                'translation_strategy' => 'attribute',
            ),
        ),
    ));
    

Caution

Changing this setting when data was already persisted with a different translation strategy will require manually updating the current data to match that of the chosen translation strategy.

See the PHPCR-ODM documentation for more information.

Editing Locale Information: Translatable Sonata Admin Extension

Several bundles provide translatable model classes that implement TranslatableInterface. This extension adds a locale field to the given SonataAdminBundle forms.

To enable the extensions in your admin classes, simply define the extension configuration in the sonata_admin section of your project configuration:

  • YAML
    1
    2
    3
    4
    5
    6
    7
    # app/config/config.yml
    sonata_admin:
        # ...
        extensions:
            cmf_core.admin_extension.translatable:
                implements:
                    - Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface
    
  • XML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    <!-- app/config/config.xml -->
    <?xml version="1.0" charset="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services">
        <config xmlns="http://sonata-project.org/schema/dic/admin">
            <!-- ... -->
            <extension id="cmf_core.admin_extension.translatable">
                <implement>
                    Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface
                </implement>
            </extension>
        </config>
    
    </container>
    
  • PHP
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    // app/config/config.php
    $container->loadFromExtension('sonata_admin', array(
        // ...
        'extensions' => array(
            'cmf_core.admin_extension.translatable' => array(
                'implements' => array(
                    'Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface',
                ),
            ),
        ),
    ));
    

See the Sonata Admin extension documentation for more information.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.