PageRenderTime 68ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/framework/Data/Form/Element/Multiline.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 152 lines | 112 code | 9 blank | 31 comment | 14 complexity | 8f6d96932279d5065deeace0550702ba MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Form multiline text elements
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Framework\Data\Form\Element;
  12. use Magento\Framework\Escaper;
  13. class Multiline extends AbstractElement
  14. {
  15. /**
  16. * @param Factory $factoryElement
  17. * @param CollectionFactory $factoryCollection
  18. * @param Escaper $escaper
  19. * @param array $data
  20. */
  21. public function __construct(
  22. Factory $factoryElement,
  23. CollectionFactory $factoryCollection,
  24. Escaper $escaper,
  25. $data = []
  26. ) {
  27. parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
  28. $this->setType('text');
  29. $this->setLineCount(2);
  30. }
  31. /**
  32. * @return string[]
  33. */
  34. public function getHtmlAttributes()
  35. {
  36. return [
  37. 'type',
  38. 'title',
  39. 'class',
  40. 'style',
  41. 'onclick',
  42. 'onchange',
  43. 'disabled',
  44. 'maxlength',
  45. 'data-form-part',
  46. 'data-role',
  47. 'data-action'
  48. ];
  49. }
  50. /**
  51. * @param int $suffix
  52. * @return string
  53. */
  54. public function getLabelHtml($suffix = 0)
  55. {
  56. return parent::getLabelHtml($suffix);
  57. }
  58. /**
  59. * Get element HTML
  60. *
  61. * @return string
  62. */
  63. public function getElementHtml()
  64. {
  65. $html = '';
  66. $lineCount = $this->getLineCount();
  67. for ($i = 0; $i < $lineCount; $i++) {
  68. if ($i == 0 && $this->getRequired()) {
  69. $this->setClass('input-text admin__control-text required-entry _required');
  70. } else {
  71. $this->setClass('input-text admin__control-text');
  72. }
  73. $html .= '<div class="multi-input admin__field-control"><input id="' .
  74. $this->getHtmlId() .
  75. $i .
  76. '" name="' .
  77. $this->getName() .
  78. '[' .
  79. $i .
  80. ']' .
  81. '" value="' .
  82. $this->getEscapedValue(
  83. $i
  84. ) . '" ' . $this->serialize(
  85. $this->getHtmlAttributes()
  86. ) . ' ' . $this->_getUiId(
  87. $i
  88. ) . '/>' . "\n";
  89. if ($i == 0) {
  90. $html .= $this->getAfterElementHtml();
  91. }
  92. $html .= '</div>';
  93. }
  94. return $html;
  95. }
  96. /**
  97. * @return mixed
  98. * @SuppressWarnings(PHPMD.NPathComplexity)
  99. */
  100. public function getDefaultHtml()
  101. {
  102. $html = '';
  103. $lineCount = $this->getLineCount();
  104. for ($i = 0; $i < $lineCount; $i++) {
  105. $html .= $this->getNoSpan() === true ? '' : '<span class="field-row">' . "\n";
  106. if ($i == 0) {
  107. $html .= '<label for="' .
  108. $this->getHtmlId() .
  109. $i .
  110. '">' .
  111. $this->getLabel() .
  112. ($this->getRequired() ? ' <span class="required">*</span>' : '') .
  113. '</label>' .
  114. "\n";
  115. if ($this->getRequired()) {
  116. $this->setClass('input-text required-entry');
  117. }
  118. } else {
  119. $this->setClass('input-text');
  120. $html .= '<label>&nbsp;</label>' . "\n";
  121. }
  122. $html .= '<input id="' .
  123. $this->getHtmlId() .
  124. $i .
  125. '" name="' .
  126. $this->getName() .
  127. '[' .
  128. $i .
  129. ']' .
  130. '" value="' .
  131. $this->getEscapedValue(
  132. $i
  133. ) . '"' . $this->serialize(
  134. $this->getHtmlAttributes()
  135. ) . ' />' . "\n";
  136. if ($i == 0) {
  137. $html .= $this->getAfterElementHtml();
  138. }
  139. $html .= $this->getNoSpan() === true ? '' : '</span>' . "\n";
  140. }
  141. return $html;
  142. }
  143. }