MaxLengthPlugin.php 995 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license infieldation, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form\Renderer\Plugin;
  11. use Symfony\Component\Form\Renderer\RendererInterface;
  12. use Symfony\Component\Form\FieldInterface;
  13. class MaxLengthPlugin implements PluginInterface
  14. {
  15. private $maxLength;
  16. public function __construct($maxLength)
  17. {
  18. $this->maxLength = $maxLength;
  19. }
  20. /**
  21. * Renders the HTML enctype in the field tag, if necessary
  22. *
  23. * Example usage in Twig templates:
  24. *
  25. * <field action="..." method="post" {{ field.render.enctype }}>
  26. *
  27. * @param Form $field The field for which to render the encoding type
  28. */
  29. public function setUp(RendererInterface $renderer)
  30. {
  31. $renderer->setVar('max_length', $this->maxLength);
  32. }
  33. }