Adding TranslatableStringFormType.php

This commit is contained in:
Marc Ducobu 2014-11-08 11:04:35 +01:00
parent 394decb579
commit b0ac03acd7
4 changed files with 57 additions and 9 deletions

View File

@ -23,8 +23,11 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('cl_chill_main.installation_name',
$config['installation_name']);
$container->setParameter('chill_main.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->load('services.yml');

View File

@ -21,12 +21,15 @@ class Configuration implements ConfigurationInterface
$rootNode = $treeBuilder->root('cl_chill_main');
$rootNode
->children()
->scalarNode('installation_name')
->cannotBeEmpty()
->defaultValue('Chill')
->end()
->end();
->children()
->scalarNode('installation_name')
->cannotBeEmpty()
->defaultValue('Chill')
->end()
->arrayNode('available_languages')
->prototype('scalar')->end()
->end()
->end();
return $treeBuilder;
}

View 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';
}
}

View File

@ -7,7 +7,7 @@ services:
#must be set in function to avoid circular reference with chill.main.twig.chill_menu
calls:
- [setContainer, ["@service_container"]]
chill.main.twig.chill_menu:
class: Chill\MainBundle\Routing\MenuTwig
arguments:
@ -16,3 +16,12 @@ services:
- [setContainer, ["@service_container"]]
tags:
- { 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 }