You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GalleryManagerField.php 3.1KB

3 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\Type\FileManagerType;
  6. use Lc\SovBundle\Form\Type\GalleryManagerType;
  7. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  8. class GalleryManagerField implements FieldInterface
  9. {
  10. use FieldTrait;
  11. public const OPTION_ALLOW_ADD = 'allowAdd';
  12. public const OPTION_ALLOW_DELETE = 'allowDelete';
  13. public const OPTION_ENTRY_IS_COMPLEX = 'entryIsComplex';
  14. public const OPTION_ENTRY_TYPE = 'entryType';
  15. public const OPTION_SHOW_ENTRY_LABEL = 'showEntryLabel';
  16. public static function new(string $propertyName, ?string $label = null): self
  17. {
  18. return (new self())
  19. ->setProperty($propertyName)
  20. ->setLabel($label)
  21. ->setTemplatePath('@LcSov/tabler/crud/field/collection.html.twig')
  22. ->setFormType(CollectionType::class)
  23. ->addCssClass('field-collection')
  24. ->addWebpackEncoreEntries('field-collection')
  25. ->addWebpackEncoreEntries('field-filemanager')
  26. ->setFormTypeOption('allow_add', true)
  27. ->setFormTypeOption('allow_delete', true)
  28. ->setFormTypeOption('entry_options', array('label'=> false))
  29. ->setFormTypeOption('entry_type', FileManagerType::class)
  30. ->setFormTypeOption('attr', array('class'=> 'field-collection-group'))
  31. ->setFormTypeOption('row_attr', array('data-sortable'=> true))
  32. ->hideOnIndex();
  33. //->setEntryType(FileManagerType::class);
  34. //->setFormTypeOption('show_entry_label', false);
  35. }
  36. public function allowAdd(bool $allow = true): self
  37. {
  38. $this->setCustomOption(self::OPTION_ALLOW_ADD, $allow);
  39. return $this;
  40. }
  41. public function allowDelete(bool $allow = true): self
  42. {
  43. $this->setCustomOption(self::OPTION_ALLOW_DELETE, $allow);
  44. return $this;
  45. }
  46. /**
  47. * Set this option to TRUE if the collection items are complex form types
  48. * composed of several form fields (EasyAdmin applies a special rendering to make them look better).
  49. */
  50. public function setEntryIsComplex(bool $isComplex): self
  51. {
  52. $this->setCustomOption(self::OPTION_ENTRY_IS_COMPLEX, $isComplex);
  53. return $this;
  54. }
  55. public function setEntryType(string $formTypeFqcn): self
  56. {
  57. $this->setCustomOption(self::OPTION_ENTRY_TYPE, $formTypeFqcn);
  58. return $this;
  59. }
  60. public function showEntryLabel(bool $showLabel = true): self
  61. {
  62. $this->setCustomOption(self::OPTION_SHOW_ENTRY_LABEL, $showLabel);
  63. return $this;
  64. }
  65. }