Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ImageManagerField.php 1.9KB

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