-
-
Save aitboudad/02db0ef89300991503fd287fb6ce3eec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
app.upload_type_extension: | |
class: Symfony\Component\Form\Extension\Validator\Type\UploadValidatorExtension | |
arguments: ['@translator', '%validator.translation_domain%'] | |
tags: | |
- { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file is part of the Symfony package. | |
* | |
* (c) Fabien Potencier <fabien@symfony.com> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace Symfony\Component\Form\Extension\Validator\Type; | |
use Symfony\Component\OptionsResolver\Options; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
use Symfony\Component\Translation\TranslatorInterface; | |
use Symfony\Component\Form\AbstractTypeExtension; | |
use Symfony\Component\Form\Extension\Core\Type\FormType; | |
/** | |
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com> | |
*/ | |
class UploadValidatorExtension extends AbstractTypeExtension | |
{ | |
private $translator; | |
private $translationDomain; | |
/** | |
* @param TranslatorInterface $translator The translator for translating error messages | |
* @param null|string $translationDomain The translation domain for translating | |
*/ | |
public function __construct(TranslatorInterface $translator, $translationDomain = null) | |
{ | |
$this->translator = $translator; | |
$this->translationDomain = $translationDomain; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function configureOptions(OptionsResolver $resolver) | |
{ | |
$resolver->setNormalizer('post_max_size_message', function (Options $options, $errorMessage) { | |
return $this->translator->trans($errorMessage, array(), $this->translationDomain); | |
}); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getExtendedType() | |
{ | |
return FormType::class; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment