Textarea.php 669 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Dcat\Admin\Form\Field;
  3. use Dcat\Admin\Form\Field;
  4. class Textarea extends Field
  5. {
  6. /**
  7. * Default rows of textarea.
  8. *
  9. * @var int
  10. */
  11. protected $rows = 5;
  12. /**
  13. * Set rows of textarea.
  14. *
  15. * @param int $rows
  16. *
  17. * @return $this
  18. */
  19. public function rows($rows = 5)
  20. {
  21. $this->rows = $rows;
  22. return $this;
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function render()
  28. {
  29. if (is_array($this->value)) {
  30. $this->value = json_encode($this->value, JSON_PRETTY_PRINT);
  31. }
  32. return parent::render()->with(['rows' => $this->rows]);
  33. }
  34. }