allow forms without translations and validator

This commit is contained in:
Christian Flothmann 2017-09-24 10:13:45 +01:00
parent 4badda981e
commit cb6ead1635
2 changed files with 13 additions and 7 deletions

View File

@ -74,6 +74,7 @@ use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintCommand;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\ObjectInitializerInterface;
use Symfony\Component\WebLink\HttpHeaderSerializer;
@ -189,15 +190,13 @@ class FrameworkExtension extends Extension
throw new LogicException('Translation support cannot be enabled as the Translation component is not installed.');
}
if (!class_exists('Symfony\Component\Translation\Translator') && $this->isConfigEnabled($container, $config['form'])) {
throw new LogicException('Form support cannot be enabled as the Translation component is not installed.');
}
if (!class_exists('Symfony\Component\Translation\Translator') && $this->isConfigEnabled($container, $config['validation'])) {
throw new LogicException('Validation support cannot be enabled as the Translation component is not installed.');
}
$loader->load('identity_translator.xml');
if (class_exists(Translator::class)) {
$loader->load('identity_translator.xml');
}
}
if (isset($config['secret'])) {
@ -250,7 +249,10 @@ class FrameworkExtension extends Extension
$config['validation']['enabled'] = true;
if (!class_exists('Symfony\Component\Validator\Validation')) {
throw new LogicException('The Validator component is required to use the Form component.');
$container->setParameter('validator.translation_domain', 'validators');
$container->removeDefinition('form.type_extension.form.validator');
$container->removeDefinition('form.type_guesser.validator');
}
} else {
$container->removeDefinition('Symfony\Component\Form\Command\DebugCommand');
@ -448,6 +450,10 @@ class FrameworkExtension extends Extension
} else {
$container->setParameter('form.type_extension.csrf.enabled', false);
}
if (!class_exists(Translator::class)) {
$container->removeDefinition('form.type_extension.upload.validator');
}
}
/**

View File

@ -12,7 +12,7 @@
<argument type="service" id="security.csrf.token_manager" />
<argument>%form.type_extension.csrf.enabled%</argument>
<argument>%form.type_extension.csrf.field_name%</argument>
<argument type="service" id="translator" />
<argument type="service" id="translator" on-invalid="null" />
<argument>%validator.translation_domain%</argument>
<argument type="service" id="form.server_params" />
</service>