Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

42 lines
1.4KB

  1. <?php
  2. namespace Lc\SovBundle\Field;
  3. use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
  5. use FOS\CKEditorBundle\Form\Type\CKEditorType;
  6. /**
  7. * @author Javier Eguiluz <javier.eguiluz@gmail.com>
  8. */
  9. final class CKEditorField implements FieldInterface
  10. {
  11. use FieldTrait;
  12. public const OPTION_NUM_OF_ROWS = 'numOfRows';
  13. public static function new(string $propertyName, ?string $label = null): self
  14. {
  15. return (new self())
  16. ->setProperty($propertyName)
  17. ->setLabel($label)
  18. ->setTemplateName('crud/field/text_editor')
  19. ->setFormType(CKEditorType::class)
  20. ->addCssClass('field-text_editor')
  21. ->addCssFiles('bundles/easyadmin/form-type-text-editor.css')
  22. ->addJsFiles('bundles/easyadmin/form-type-text-editor.js')
  23. ->setCustomOption(self::OPTION_NUM_OF_ROWS, null);
  24. }
  25. public function setNumOfRows(int $rows): self
  26. {
  27. if ($rows < 1) {
  28. throw new \InvalidArgumentException(sprintf('The argument of the "%s()" method must be 1 or higher (%d given).', __METHOD__, $rows));
  29. }
  30. $this->setCustomOption(self::OPTION_NUM_OF_ROWS, $rows);
  31. return $this;
  32. }
  33. }