1: <?php
2:
3: 4: 5:
6: class Quform_Element_Textarea extends Quform_Element_Field implements Quform_Element_Editable
7: {
8: 9: 10: 11: 12: 13:
14: public function setDefaultValue($value, $replacePlaceholders = true)
15: {
16: $this->defaultValue = $replacePlaceholders ? $this->getForm()->replaceVariablesPreProcess($value) : $value;
17: }
18:
19: 20: 21: 22: 23:
24: public function getValueHtml()
25: {
26: $value = nl2br(Quform::escape($this->getValue()));
27:
28: $value = apply_filters('quform_get_value_html_' . $this->getIdentifier(), $value, $this, $this->getForm());
29:
30: return $value;
31: }
32:
33: 34: 35: 36: 37: 38:
39: protected function getFieldAttributes(array $context = array())
40: {
41: $attributes = array(
42: 'id' => $this->getUniqueId(),
43: 'name' => $this->getFullyQualifiedName(),
44: 'class' => Quform::sanitizeClass($this->getFieldClasses($context))
45: );
46:
47: $placeholder = $this->form->replaceVariablesPreProcess($this->config('placeholder'));
48: if (Quform::isNonEmptyString($placeholder)) {
49: $attributes['placeholder'] = $placeholder;
50: }
51:
52: if (Quform::isNonEmptyString($this->config('autocomplete'))) {
53: $attributes['autocomplete'] = $this->config('autocomplete');
54: }
55:
56: if (Quform::isNonEmptyString($this->config('maxLength'))) {
57: $attributes['maxlength'] = $this->config('maxLength');
58: }
59:
60: if ($this->config('readOnly')) {
61: $attributes['readonly'] = true;
62: }
63:
64: $attributes = apply_filters('quform_field_attributes', $attributes, $this, $this->form, $context);
65: $attributes = apply_filters('quform_field_attributes_' . $this->getIdentifier(), $attributes, $this, $this->form, $context);
66:
67: return $attributes;
68: }
69:
70: 71: 72: 73: 74: 75:
76: protected function getFieldClasses(array $context = array())
77: {
78: $classes = array(
79: 'quform-field',
80: 'quform-field-textarea',
81: sprintf('quform-field-%s', $this->getIdentifier())
82: );
83:
84: if ($this->form->config('tooltipsEnabled') && Quform::isNonEmptyString($this->config('tooltip')) && Quform::get($context, 'tooltipType') == 'field') {
85: $classes[] = sprintf('quform-tooltip-%s', Quform::get($context, 'tooltipEvent'));
86: }
87:
88: if (Quform::isNonEmptyString($this->config('customClass'))) {
89: $classes[] = $this->config('customClass');
90: }
91:
92: $classes = apply_filters('quform_field_classes', $classes, $this, $this->form, $context);
93: $classes = apply_filters('quform_field_classes_' . $this->getIdentifier(), $classes, $this, $this->form, $context);
94:
95: return $classes;
96: }
97:
98: 99: 100: 101: 102: 103:
104: protected function getFieldHtml(array $context = array())
105: {
106: if ($this->config('enableEditor')) {
107: ob_start();
108:
109: $settings = apply_filters('quform_textarea_editor_settings', array());
110: $settings = apply_filters('quform_textarea_editor_settings_' . $this->getIdentifier(), $settings);
111: $settings['textarea_name'] = $this->getFullyQualifiedName();
112:
113: wp_editor($this->getValue(), $this->getUniqueId(), $settings);
114:
115: return ob_get_clean();
116: }
117:
118: return Quform::getHtmlTag('textarea', $this->getFieldAttributes($context), Quform::escape($this->getValue()));
119: }
120:
121: 122: 123: 124: 125:
126: public function getEditFieldHtml()
127: {
128: return $this->getFieldHtml();
129: }
130:
131: 132: 133: 134: 135: 136:
137: protected function renderCss(array $context = array())
138: {
139: $css = parent::renderCss($context);
140:
141: if ($context['fieldWidth'] == 'custom' && Quform::isNonEmptyString($context['fieldWidthCustom'])) {
142: $css .= sprintf('.quform-input-textarea.quform-input-%s { width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
143: $css .= sprintf('.quform-inner-%s > .quform-error > .quform-error-inner { float: left; min-width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
144: }
145:
146: return $css;
147: }
148:
149: 150: 151: 152: 153: 154:
155: public static function getDefaultConfig($key = null)
156: {
157: $config = apply_filters('quform_default_config_textarea', array(
158:
159: 'label' => __('Untitled', 'quform'),
160: 'description' => '',
161: 'descriptionAbove' => '',
162: 'required' => false,
163:
164:
165: 'labelIcon' => '',
166: 'fieldIconLeft' => '',
167: 'fieldIconRight' => '',
168: 'fieldSize' => 'inherit',
169: 'fieldWidth' => 'inherit',
170: 'fieldWidthCustom' => '',
171: 'enableEditor' => false,
172: 'customClass' => '',
173: 'customElementClass' => '',
174: 'styles' => array(),
175:
176:
177: 'placeholder' => '',
178: 'subLabel' => '',
179: 'subLabelAbove' => '',
180: 'adminLabel' => '',
181: 'tooltip' => '',
182: 'tooltipType' => 'inherit',
183: 'tooltipEvent' => 'inherit',
184: 'labelPosition' => 'inherit',
185: 'labelWidth' => '',
186:
187:
188: 'logicEnabled' => false,
189: 'logicAction' => true,
190: 'logicMatch' => 'all',
191: 'logicRules' => array(),
192:
193:
194: 'defaultValue' => '',
195: 'dynamicDefaultValue' => false,
196: 'dynamicKey' => '',
197: 'autocomplete' => '',
198: 'maxLength' => '',
199: 'readOnly' => false,
200: 'showInEmail' => true,
201: 'saveToDatabase' => true,
202:
203:
204: 'visibility' => '',
205: 'filters' => array(array('type' => 'trim')),
206: 'validators' => array(),
207:
208:
209: 'messageRequired' => '',
210: 'messageLengthTooLong' => ''
211: ));
212:
213: $config['type'] = 'textarea';
214:
215: if (Quform::isNonEmptyString($key)) {
216: return Quform::get($config, $key);
217: }
218:
219: return $config;
220: }
221: }
222: