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