Textarea.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Form textarea element
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Framework\Data\Form\Element;
  12. use Magento\Framework\Escaper;
  13. class Textarea extends AbstractElement
  14. {
  15. /**
  16. * Default number of rows
  17. */
  18. const DEFAULT_ROWS = 2;
  19. /**
  20. * Default number of columns
  21. */
  22. const DEFAULT_COLS = 15;
  23. /**
  24. * @param Factory $factoryElement
  25. * @param CollectionFactory $factoryCollection
  26. * @param Escaper $escaper
  27. * @param array $data
  28. */
  29. public function __construct(
  30. Factory $factoryElement,
  31. CollectionFactory $factoryCollection,
  32. Escaper $escaper,
  33. $data = []
  34. ) {
  35. parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
  36. $this->setType('textarea');
  37. $this->setExtType('textarea');
  38. if (!$this->getRows()) {
  39. $this->setRows(self::DEFAULT_ROWS);
  40. }
  41. if (!$this->getCols()) {
  42. $this->setCols(self::DEFAULT_COLS);
  43. }
  44. }
  45. /**
  46. * Return the HTML attributes
  47. *
  48. * @return string[]
  49. */
  50. public function getHtmlAttributes()
  51. {
  52. return [
  53. 'title',
  54. 'class',
  55. 'style',
  56. 'onclick',
  57. 'onchange',
  58. 'rows',
  59. 'cols',
  60. 'readonly',
  61. 'disabled',
  62. 'onkeyup',
  63. 'tabindex',
  64. 'data-form-part',
  65. 'data-role',
  66. 'data-action'
  67. ];
  68. }
  69. /**
  70. * Return the element as HTML
  71. *
  72. * @return string
  73. */
  74. public function getElementHtml()
  75. {
  76. $this->addClass('textarea admin__control-textarea');
  77. $html = '<textarea id="' . $this->getHtmlId() . '" name="' . $this->getName() . '" '
  78. . $this->serialize($this->getHtmlAttributes()) . $this->_getUiId() . ' >';
  79. $html .= $this->getEscapedValue();
  80. $html .= "</textarea>";
  81. $html .= $this->getAfterElementHtml();
  82. return $html;
  83. }
  84. }