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