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

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.  * @author Nicolas Bastien <nbastien.pro@gmail.com>
  17.  */
  18. class Configuration implements ConfigurationInterface
  19. {
  20.     /**
  21.      * {@inheritdoc}
  22.      */
  23.     public function getConfigTreeBuilder()
  24.     {
  25.         $treeBuilder = new TreeBuilder('sonata_translation');
  26.         // Keep compatibility with symfony/config < 4.2
  27.         if (!method_exists($treeBuilder'getRootNode')) {
  28.             $rootNode $treeBuilder->root('sonata_translation');
  29.         } else {
  30.             $rootNode $treeBuilder->getRootNode();
  31.         }
  32.         $rootNode
  33.             ->children()
  34.                 ->arrayNode('locales')
  35.                     ->info('The list of your frontend locales in which your models will be translatable.')
  36.                     ->requiresAtLeastOneElement()
  37.                     ->prototype('scalar')->end()
  38.                 ->end()
  39.                 ->scalarNode('default_locale')
  40.                     ->defaultValue('en')
  41.                     ->info('The frontend locale that is used by default.')
  42.                 ->end()
  43.                 ->enumNode('default_filter_mode')
  44.                     ->values(TranslationFilterMode::AVAILABLE_FILTER_TYPES)
  45.                     ->defaultValue(TranslationFilterMode::GEDMO)
  46.                     ->info('The filter mode that is used by default.')
  47.                 ->end()
  48.                 ->arrayNode('gedmo')
  49.                     ->canBeEnabled()
  50.                     ->children()
  51.                         ->arrayNode('implements')
  52.                             ->requiresAtLeastOneElement()
  53.                             ->prototype('scalar')->end()
  54.                         ->end()
  55.                         ->arrayNode('instanceof')
  56.                             ->requiresAtLeastOneElement()
  57.                             ->prototype('scalar')->end()
  58.                         ->end()
  59.                     ->end()
  60.                 ->end()
  61.                 ->arrayNode('knplabs')
  62.                     ->canBeEnabled()
  63.                     ->children()
  64.                         ->arrayNode('implements')
  65.                             ->requiresAtLeastOneElement()
  66.                             ->prototype('scalar')->end()
  67.                         ->end()
  68.                         ->arrayNode('instanceof')
  69.                             ->requiresAtLeastOneElement()
  70.                             ->prototype('scalar')->end()
  71.                         ->end()
  72.                     ->end()
  73.                 ->end()
  74.                 ->arrayNode('phpcr')
  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.                 ->booleanNode('locale_switcher')
  88.                     ->info('Enable the global locale switcher services.')
  89.                     ->defaultFalse()
  90.                 ->end()
  91.                 // NEXT_MAJOR: Fix locale to country flag mapping OR remove country flags entirely
  92.                 ->booleanNode('locale_switcher_show_country_flags')
  93.                     ->info('Whether the language switcher should show languages as flags')
  94.                     ->defaultTrue()
  95.                 ->end()
  96.             ->end()
  97.             ->beforeNormalization()
  98.                 ->ifTrue(static function ($v) {return !isset($v['locale_switcher_show_country_flags']) || true === $v['locale_switcher_show_country_flags']; })
  99.                 ->then(static function ($v) {
  100.                     @trigger_error(sprintf(
  101.                         '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.',
  102.                         'sonata_translation.locale_switcher_show_country_flags'
  103.                     ), E_USER_DEPRECATED);
  104.                     $v['locale_switcher_show_country_flags'] = $v['locale_switcher_show_country_flags'] ?? true;
  105.                     return $v;
  106.                 })
  107.             ->end();
  108.         return $treeBuilder;
  109.     }
  110. }