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,9 +23,12 @@ 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');
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,9 @@ class Configuration implements ConfigurationInterface
|
|||||||
->cannotBeEmpty()
|
->cannotBeEmpty()
|
||||||
->defaultValue('Chill')
|
->defaultValue('Chill')
|
||||||
->end()
|
->end()
|
||||||
|
->arrayNode('available_languages')
|
||||||
|
->prototype('scalar')->end()
|
||||||
|
->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';
|
||||||
|
}
|
||||||
|
}
|
@ -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