feature #24303 [FrameworkBundle] allow forms without translations and validator (xabbuh)
This PR was merged into the 3.4 branch.
Discussion
----------
[FrameworkBundle] allow forms without translations and validator
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | symfony/flex#26, symfony/recipes#191, symfony/recipes#193
| License | MIT
| Doc PR |
The Form component is perfectly usable without the Translation and Validator components. We should allow the same when using the FrameworkBundle to improve the user experience in Symfony Flex applications (see the linked issue).
Commits
-------
cb6ead1635
allow forms without translations and validator
This commit is contained in:
commit
b590683836
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user