vendor/sonata-project/translation-bundle/src/DependencyInjection/Configuration.php line 124

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\TranslationBundle\DependencyInjection;
  12. use Sonata\TranslationBundle\Enum\TranslationFilterMode;
  13. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  14. use Symfony\Component\Config\Definition\ConfigurationInterface;
  15. /**
  16.  * @final since sonata-project/translation-bundle 2.7
  17.  *
  18.  * @author Nicolas Bastien <nbastien.pro@gmail.com>
  19.  */
  20. class Configuration implements ConfigurationInterface
  21. {
  22.     /**
  23.      * @psalm-suppress PossiblyNullReference, PossiblyUndefinedMethod
  24.      *
  25.      * @see https://github.com/psalm/psalm-plugin-symfony/issues/174
  26.      */
  27.     public function getConfigTreeBuilder()
  28.     {
  29.         $treeBuilder = new TreeBuilder('sonata_translation');
  30.         $rootNode $treeBuilder->getRootNode();
  31.         $rootNode
  32.             ->children()
  33.                 ->arrayNode('locales')
  34.                     ->info('The list of your frontend locales in which your models will be translatable.')
  35.                     ->requiresAtLeastOneElement()
  36.                     ->prototype('scalar')->end()
  37.                 ->end()
  38.                 ->scalarNode('default_locale')
  39.                     ->defaultValue('en')
  40.                     ->info('The frontend locale that is used by default.')
  41.                 ->end()
  42.                 ->enumNode('default_filter_mode')
  43.                     ->values(TranslationFilterMode::AVAILABLE_FILTER_TYPES)
  44.                     ->defaultValue(TranslationFilterMode::GEDMO)
  45.                     ->info('The filter mode that is used by default.')
  46.                 ->end()
  47.                 ->arrayNode('gedmo')
  48.                     ->canBeEnabled()
  49.                     ->children()
  50.                         ->arrayNode('implements')
  51.                             ->requiresAtLeastOneElement()
  52.                             ->prototype('scalar')->end()
  53.                         ->end()
  54.                         ->arrayNode('instanceof')
  55.                             ->requiresAtLeastOneElement()
  56.                             ->prototype('scalar')->end()
  57.                         ->end()
  58.                         ->scalarNode('translatable_listener_service')
  59.                             ->info('Custom translatable listener service name when using gedmo/doctrine-extensions')
  60.                             // NEXT_MAJOR: Remove default value.
  61.                             ->defaultValue(static function (): string {
  62.                                 @trigger_error(
  63.                                     'Not specifying the translatable listener service when using'
  64.                                     .' gedmo/doctrine-extensions is deprecated since sonata-project/translation-bundle 2.8.'
  65.                                     .' If you are using a bundle that integrates this library, it is likely that it'
  66.                                     .' registers that service for you. In case of "stof/doctrine-extensions-bundle", it is:'
  67.                                     .' "stof_doctrine_extensions.listener.translatable".'
  68.                                 );
  69.                                 return 'stof_doctrine_extensions.listener.translatable';
  70.                             })
  71.                         ->end()
  72.                     ->end()
  73.                 ->end()
  74.                 ->arrayNode('knplabs')
  75.                     ->canBeEnabled()
  76.                     ->children()
  77.                         ->arrayNode('implements')
  78.                             ->requiresAtLeastOneElement()
  79.                             ->prototype('scalar')->end()
  80.                         ->end()
  81.                         ->arrayNode('instanceof')
  82.                             ->requiresAtLeastOneElement()
  83.                             ->prototype('scalar')->end()
  84.                         ->end()
  85.                     ->end()
  86.                 ->end()
  87.                 ->arrayNode('phpcr')
  88.                     ->canBeEnabled()
  89.                     ->children()
  90.                         ->arrayNode('implements')
  91.                             ->requiresAtLeastOneElement()
  92.                             ->prototype('scalar')->end()
  93.                         ->end()
  94.                         ->arrayNode('instanceof')
  95.                             ->requiresAtLeastOneElement()
  96.                             ->prototype('scalar')->end()
  97.                         ->end()
  98.                     ->end()
  99.                 ->end()
  100.                 ->booleanNode('locale_switcher')
  101.                     ->info('Enable the global locale switcher services.')
  102.                     ->defaultFalse()
  103.                 ->end()
  104.                 // NEXT_MAJOR: Fix locale to country flag mapping OR remove country flags entirely
  105.                 ->booleanNode('locale_switcher_show_country_flags')
  106.                     ->info('Whether the language switcher should show languages as flags')
  107.                     ->defaultTrue()
  108.                 ->end()
  109.             ->end()
  110.             ->beforeNormalization()
  111.                 ->ifTrue(static function ($v) {return !isset($v['locale_switcher_show_country_flags']) || true === $v['locale_switcher_show_country_flags']; })
  112.                 ->then(static function ($v) {
  113.                     @trigger_error(sprintf(
  114.                         'Showing the country flags is deprecated. The flags will be removed in the next major version. Please set "%s" to false to avoid this message.',
  115.                         'sonata_translation.locale_switcher_show_country_flags'
  116.                     ), \E_USER_DEPRECATED);
  117.                     $v['locale_switcher_show_country_flags'] = $v['locale_switcher_show_country_flags'] ?? true;
  118.                     return $v;
  119.                 })
  120.             ->end();
  121.         return $treeBuilder;
  122.     }
  123. }