No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

ImageManagerField.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Lc\SovBundle\Field;
  3. use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
  5. use Lc\SovBundle\Form\Common\FileManagerType;
  6. /**
  7. * @author La clic ! <contact@laclic.fr>
  8. */
  9. final class ImageManagerField implements FieldInterface
  10. {
  11. use FieldTrait;
  12. public const OPTION_MAX_LENGTH = 'maxLength';
  13. public const OPTION_RENDER_AS_HTML = 'renderAsHtml';
  14. public static function new(string $propertyName, ?string $label = null): self
  15. {
  16. return (new self())
  17. ->setProperty($propertyName)
  18. ->setLabel($label)
  19. ->setTemplatePath('@LcSov/adminlte/crud/field/image.html.twig')
  20. //->addWebpackEncoreEntries('adminlte-field-filemanager')
  21. ->setFormType(FileManagerType::class)
  22. ->setCustomOption('managerDir', 'image')
  23. ->setCustomOption('type', 'image')
  24. ->addCssClass('field-text')
  25. ->setCustomOption(self::OPTION_MAX_LENGTH, null)
  26. ->setCustomOption(self::OPTION_RENDER_AS_HTML, false);
  27. }
  28. public function setMaxLength(int $length): self
  29. {
  30. if ($length < 1) {
  31. throw new \InvalidArgumentException(sprintf('The argument of the "%s()" method must be 1 or higher (%d given).', __METHOD__, $length));
  32. }
  33. $this->setCustomOption(self::OPTION_MAX_LENGTH, $length);
  34. return $this;
  35. }
  36. public function renderAsHtml(bool $asHtml = true): self
  37. {
  38. $this->setCustomOption(self::OPTION_RENDER_AS_HTML, $asHtml);
  39. return $this;
  40. }
  41. }