Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

84 lines
3.0KB

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