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.

40 lines
1.3KB

  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. ->setCustomOption(self::OPTION_NUM_OF_ROWS, null);
  22. }
  23. public function setNumOfRows(int $rows): self
  24. {
  25. if ($rows < 1) {
  26. throw new \InvalidArgumentException(sprintf('The argument of the "%s()" method must be 1 or higher (%d given).', __METHOD__, $rows));
  27. }
  28. $this->setCustomOption(self::OPTION_NUM_OF_ROWS, $rows);
  29. return $this;
  30. }
  31. }