mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Adding TranslatableStringFormType.php
This commit is contained in:
parent
394decb579
commit
b0ac03acd7
@ -23,8 +23,11 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface
|
|||||||
$configuration = new Configuration();
|
$configuration = new Configuration();
|
||||||
$config = $this->processConfiguration($configuration, $configs);
|
$config = $this->processConfiguration($configuration, $configs);
|
||||||
|
|
||||||
$container->setParameter('cl_chill_main.installation_name',
|
$container->setParameter('chill_main.installation_name',
|
||||||
$config['installation_name']);
|
$config['installation_name']);
|
||||||
|
|
||||||
|
$container->setParameter('chill_main.available_languages',
|
||||||
|
$config['available_languages']);
|
||||||
|
|
||||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||||
$loader->load('services.yml');
|
$loader->load('services.yml');
|
||||||
|
@ -21,12 +21,15 @@ class Configuration implements ConfigurationInterface
|
|||||||
$rootNode = $treeBuilder->root('cl_chill_main');
|
$rootNode = $treeBuilder->root('cl_chill_main');
|
||||||
|
|
||||||
$rootNode
|
$rootNode
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('installation_name')
|
->scalarNode('installation_name')
|
||||||
->cannotBeEmpty()
|
->cannotBeEmpty()
|
||||||
->defaultValue('Chill')
|
->defaultValue('Chill')
|
||||||
->end()
|
->end()
|
||||||
->end();
|
->arrayNode('available_languages')
|
||||||
|
->prototype('scalar')->end()
|
||||||
|
->end()
|
||||||
|
->end();
|
||||||
|
|
||||||
return $treeBuilder;
|
return $treeBuilder;
|
||||||
}
|
}
|
||||||
|
33
Form/Type/TranslatableStringFormType.php
Normal file
33
Form/Type/TranslatableStringFormType.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Form\Type;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
|
||||||
|
class TranslatableStringFormType extends AbstractType
|
||||||
|
{
|
||||||
|
private $availableLanguages; // The langauges availaible
|
||||||
|
private $frameworkTranslatorFallback; // The langagues used for the translation
|
||||||
|
|
||||||
|
public function __construct(array $availableLanguages, $frameworkTranslatorFallback) {
|
||||||
|
$this->availableLanguages = $availableLanguages;
|
||||||
|
$this->frameworkTranslatorFallback = $frameworkTranslatorFallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options) {
|
||||||
|
foreach ($this->availableLanguages as $lang) {
|
||||||
|
$builder->add($lang, 'text',
|
||||||
|
array('required' => ($lang === $this->frameworkTranslatorFallback)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return 'translatable_string';
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ services:
|
|||||||
#must be set in function to avoid circular reference with chill.main.twig.chill_menu
|
#must be set in function to avoid circular reference with chill.main.twig.chill_menu
|
||||||
calls:
|
calls:
|
||||||
- [setContainer, ["@service_container"]]
|
- [setContainer, ["@service_container"]]
|
||||||
|
|
||||||
chill.main.twig.chill_menu:
|
chill.main.twig.chill_menu:
|
||||||
class: Chill\MainBundle\Routing\MenuTwig
|
class: Chill\MainBundle\Routing\MenuTwig
|
||||||
arguments:
|
arguments:
|
||||||
@ -16,3 +16,12 @@ services:
|
|||||||
- [setContainer, ["@service_container"]]
|
- [setContainer, ["@service_container"]]
|
||||||
tags:
|
tags:
|
||||||
- { name: twig.extension }
|
- { name: twig.extension }
|
||||||
|
|
||||||
|
chill.main.form.type.translatable.string:
|
||||||
|
class: Chill\MainBundle\Form\Type\TranslatableStringFormType
|
||||||
|
arguments:
|
||||||
|
- "%chill_main.available_languages%"
|
||||||
|
#- "%framework.translator.fallback%"
|
||||||
|
- "%locale%"
|
||||||
|
tags:
|
||||||
|
- { name: form.type, alias: translatable_string }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user