Overview

Namespaces

  • None
  • Quform
    • Traduttore_Registry

Classes

  • Quform
  • Quform_Admin_InsertForm
  • Quform_Admin_Page
  • Quform_Admin_Page_Controller
  • Quform_Admin_Page_Dashboard
  • Quform_Admin_Page_Entries
  • Quform_Admin_Page_Entries_Edit
  • Quform_Admin_Page_Entries_List
  • Quform_Admin_Page_Entries_View
  • Quform_Admin_Page_Factory
  • Quform_Admin_Page_Forms_Add
  • Quform_Admin_Page_Forms_Edit
  • Quform_Admin_Page_Forms_List
  • Quform_Admin_Page_Help
  • Quform_Admin_Page_Preview
  • Quform_Admin_Page_Settings
  • Quform_Admin_Page_Tools
  • Quform_Admin_Page_Tools_ExportEntries
  • Quform_Admin_Page_Tools_ExportForm
  • Quform_Admin_Page_Tools_Home
  • Quform_Admin_Page_Tools_ImportForm
  • Quform_Admin_Page_Tools_Migrate
  • Quform_Admin_Page_Tools_Uninstall
  • Quform_Api
  • Quform_Block
  • Quform_Builder
  • Quform_Captcha
  • Quform_ClassLoader
  • Quform_Confirmation
  • Quform_Container
  • Quform_Dashboard_Widget
  • Quform_Dispatcher
  • Quform_Element
  • Quform_Element_Captcha
  • Quform_Element_Checkbox
  • Quform_Element_Column
  • Quform_Element_Container
  • Quform_Element_Container_Iterator
  • Quform_Element_Date
  • Quform_Element_Email
  • Quform_Element_Factory
  • Quform_Element_Field
  • Quform_Element_File
  • Quform_Element_Group
  • Quform_Element_Hidden
  • Quform_Element_Honeypot
  • Quform_Element_Html
  • Quform_Element_Multi
  • Quform_Element_Multiselect
  • Quform_Element_Name
  • Quform_Element_Page
  • Quform_Element_Password
  • Quform_Element_Radio
  • Quform_Element_Recaptcha
  • Quform_Element_Row
  • Quform_Element_Select
  • Quform_Element_Submit
  • Quform_Element_Text
  • Quform_Element_Textarea
  • Quform_Element_Time
  • Quform_Entry_Controller
  • Quform_Entry_Exporter
  • Quform_Entry_List_Settings
  • Quform_Entry_List_Table
  • Quform_Entry_Processor
  • Quform_Entry_UserSearcher
  • Quform_Filter_Abstract
  • Quform_Filter_Alpha
  • Quform_Filter_AlphaNumeric
  • Quform_Filter_Digits
  • Quform_Filter_Regex
  • Quform_Filter_Static
  • Quform_Filter_StripTags
  • Quform_Filter_Trim
  • Quform_Form
  • Quform_Form_Controller
  • Quform_Form_Exporter
  • Quform_Form_Factory
  • Quform_Form_Importer
  • Quform_Form_Iterator
  • Quform_Form_List_Settings
  • Quform_Form_List_Table
  • Quform_Form_Processor
  • Quform_License
  • Quform_Migrator
  • Quform_NonceRefresher
  • Quform_Notification
  • Quform_Notification_Resender
  • Quform_Options
  • Quform_Permissions
  • Quform_Repository
  • Quform_ScriptLoader
  • Quform_Session
  • Quform_Settings
  • Quform_Shortcode
  • Quform_Themes
  • Quform_TokenReplacer
  • Quform_Toolbar
  • Quform_Translations
  • Quform_Updater
  • Quform_Upgrader
  • Quform_Uploader
  • Quform_Validator_Abstract
  • Quform_Validator_Alpha
  • Quform_Validator_AlphaNumeric
  • Quform_Validator_Array
  • Quform_Validator_Captcha
  • Quform_Validator_Date
  • Quform_Validator_Digits
  • Quform_Validator_Duplicate
  • Quform_Validator_Email
  • Quform_Validator_FileUpload
  • Quform_Validator_GreaterThan
  • Quform_Validator_Honeypot
  • Quform_Validator_Identical
  • Quform_Validator_InArray
  • Quform_Validator_Length
  • Quform_Validator_LessThan
  • Quform_Validator_Recaptcha
  • Quform_Validator_Regex
  • Quform_Validator_Required
  • Quform_Validator_Static
  • Quform_Validator_Time
  • Quform_View
  • Quform_ViewFactory
  • Quform_Widget_Form
  • Quform_Widget_Popup

Interfaces

  • Quform_Attachable
  • Quform_Element_Editable
  • Quform_Filter_Interface
  • Quform_Validator_Interface

Constants

  • Quform\Traduttore_Registry\TRANSIENT_KEY_PLUGIN
  • Quform\Traduttore_Registry\TRANSIENT_KEY_THEME

Functions

  • Quform\Traduttore_Registry\add_project
  • Quform\Traduttore_Registry\clean_translations_cache
  • Quform\Traduttore_Registry\get_available_locales
  • Quform\Traduttore_Registry\get_installed_translations
  • Quform\Traduttore_Registry\get_translations
  • Quform\Traduttore_Registry\register_clean_translations_cache
  • Quform\Traduttore_Registry\sanitize_date
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
  5:  */
  6: class Quform_Element_Select extends Quform_Element_Multi implements Quform_Element_Editable
  7: {
  8:     /**
  9:      * Get the the HTML for an option tag
 10:      *
 11:      * @param   array   $option    The option data
 12:      * @return  string             The resulting HTML
 13:      */
 14:     protected function getOptionHtml(array $option)
 15:     {
 16:         $output = sprintf(
 17:             '<option value="%s"%s>%s</option>',
 18:             Quform::escape($this->getOptionValue($option, 'value')),
 19:             $this->hasValue($this->getOptionValue($option, 'value')) ? ' selected="selected"' : '',
 20:             Quform::escape($this->getOptionValue($option, 'label'))
 21:         );
 22: 
 23:         return $output;
 24:     }
 25: 
 26:     /**
 27:      * Get the HTML for an optgroup tag
 28:      *
 29:      * @param   array   $optgroup  The option data
 30:      * @return  string             The resulting HTML
 31:      */
 32:     protected function getOptgroupHtml(array $optgroup)
 33:     {
 34:         $output = sprintf('<optgroup label="%s">', Quform::escape($this->getOptgroupValue($optgroup, 'label')));
 35: 
 36:         foreach ($this->getOptgroupValue($optgroup, 'options') as $option) {
 37:             $output .= $this->getOptionHtml($option);
 38:         }
 39: 
 40:         $output .= '</optgroup>';
 41: 
 42:         return $output;
 43:     }
 44: 
 45:     /**
 46:      * Get the HTML attributes for the field
 47:      *
 48:      * @param   array  $context
 49:      * @return  array
 50:      */
 51:     protected function getFieldAttributes(array $context = array())
 52:     {
 53:         $attributes = array(
 54:             'id' => $this->getUniqueId(),
 55:             'name' => $this->getFullyQualifiedName(),
 56:             'class' => Quform::sanitizeClass($this->getFieldClasses($context))
 57:         );
 58: 
 59:         if ($this->config('enhancedSelectEnabled')) {
 60:             $attributes['data-options'] = wp_json_encode(array(
 61:                 'rtl' => $this->form->isRtl(),
 62:                 'search' => $this->config('enhancedSelectSearch'),
 63:                 'noResultsFound' => $this->getTranslation('enhancedSelectNoResultsFound', __('No results found.', 'quform'))
 64:             ));
 65: 
 66:             $attributes['style'] = 'width: 100%;';
 67:         }
 68: 
 69:         if (Quform::isNonEmptyString($this->config('autocomplete'))) {
 70:             $attributes['autocomplete'] = $this->config('autocomplete');
 71:         }
 72: 
 73:         if (Quform::isNonEmptyString($this->config('aria-labelledby')))  {
 74:             $attributes['aria-labelledby'] = $this->config('aria-labelledby');
 75:         }
 76: 
 77:         $attributes = apply_filters('quform_field_attributes', $attributes, $this, $this->form, $context);
 78:         $attributes = apply_filters('quform_field_attributes_' . $this->getIdentifier(), $attributes, $this, $this->form, $context);
 79: 
 80:         return $attributes;
 81:     }
 82: 
 83:     /**
 84:      * Get the classes for the field
 85:      *
 86:      * @param   array  $context
 87:      * @return  array
 88:      */
 89:     protected function getFieldClasses(array $context = array())
 90:     {
 91:         $classes = array(
 92:             'quform-field',
 93:             'quform-field-select',
 94:             sprintf('quform-field-%s', $this->getIdentifier())
 95:         );
 96: 
 97:         if ($this->config('enhancedSelectEnabled')) {
 98:             $classes[] = 'quform-field-select-enhanced';
 99:         }
100: 
101:         if (Quform::isNonEmptyString($this->config('customClass'))) {
102:             $classes[] = $this->config('customClass');
103:         }
104: 
105:         if ($this->config('submitOnChoice')) {
106:             $classes[] = 'quform-submit-on-choice';
107:         }
108: 
109:         $classes = apply_filters('quform_field_classes', $classes, $this, $this->form, $context);
110:         $classes = apply_filters('quform_field_classes_' . $this->getIdentifier(), $classes, $this, $this->form, $context);
111: 
112:         return $classes;
113:     }
114: 
115:     /**
116:      * Get the HTML for the field
117:      *
118:      * @param   array   $context
119:      * @return  string
120:      */
121:     protected function getFieldHtml(array $context = array())
122:     {
123:         return Quform::getHtmlTag('select', $this->getFieldAttributes($context), $this->getOptionsHtml());
124:     }
125: 
126:     /**
127:      * Get the HTML for the select options
128:      *
129:      * @return string
130:      */
131:     protected function getOptionsHtml()
132:     {
133:         $output = '';
134: 
135:         if ($this->config('noneOption')) {
136:             $output .= $this->getOptionHtml(array(
137:                 'label' => $this->getTranslation('noneOptionText', __('Please select', 'quform')),
138:                 'value' => ''
139:             ));
140:         }
141: 
142:         foreach ($this->getOptions() as $option) {
143:             if (isset($option['options'])) {
144:                 $output .= $this->getOptgroupHtml($option);
145:             } else {
146:                 $output .= $this->getOptionHtml($option);
147:             }
148:         }
149: 
150:         return $output;
151:     }
152: 
153:     /**
154:      * Get the field HTML when editing
155:      *
156:      * @return string
157:      */
158:     public function getEditFieldHtml()
159:     {
160:         return $this->getFieldHtml();
161:     }
162: 
163:     /**
164:      * Render the CSS for this element
165:      *
166:      * @param   array   $context
167:      * @return  string
168:      */
169:     protected function renderCss(array $context = array())
170:     {
171:         $css = parent::renderCss($context);
172: 
173:         if ($context['fieldWidth'] == 'custom' && Quform::isNonEmptyString($context['fieldWidthCustom'])) {
174:             $css .= sprintf('.quform-input-select.quform-input-%1$s, .quform-input-multiselect.quform-input-%1$s { width: %2$s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
175:             $css .= sprintf('.quform-inner-%s > .quform-error > .quform-error-inner { float: left; min-width: %s; }', $this->getIdentifier(), Quform::addCssUnit($context['fieldWidthCustom']));
176:         }
177: 
178:         return $css;
179:     }
180: 
181:     /**
182:      * Inherit settings from this element into the context
183:      *
184:      * @param   array  $context
185:      * @return  array
186:      */
187:     protected function prepareContext(array $context = array())
188:     {
189:         $context = parent::prepareContext($context);
190: 
191:         // Icon is the only possible tooltip type for this element
192:         $context['tooltipType'] = 'icon';
193: 
194:         return $context;
195:     }
196: 
197:     /**
198:      * Get the default optgroup config
199:      *
200:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
201:      * @return  array
202:      */
203:     public static function getDefaultOptgroupConfig($key = null)
204:     {
205:         $config = array(
206:             'label' => __('Untitled', 'quform'),
207:             'options' => array()
208:         );
209: 
210:         if (Quform::isNonEmptyString($key)) {
211:             return Quform::get($config, $key);
212:         }
213: 
214:         return $config;
215:     }
216: 
217:     /**
218:      * Get the value of the given $key from the given $optgroup or return the default if it does not exist
219:      *
220:      * @param   array         $optgroup
221:      * @param   string        $key
222:      * @return  string|array
223:      */
224:     protected function getOptgroupValue(array $optgroup, $key)
225:     {
226:         $value = Quform::get($optgroup, $key);
227: 
228:         if ($value === null) {
229:             $value = Quform::get(call_user_func(array(get_class($this), 'getDefaultOptgroupConfig')), $key);
230:         }
231: 
232:         return $value;
233:     }
234: 
235:     /**
236:      * Get the default options for this element
237:      *
238:      * @return array
239:      */
240:     protected static function getDefaultOptions()
241:     {
242:         $options = array();
243:         $defaults = array(__('Option 1', 'quform'), __('Option 2', 'quform'), __('Option 3', 'quform'));
244: 
245:         foreach ($defaults as $key => $value) {
246:             $option = self::getDefaultOptionConfig();
247:             $option['id'] = $key + 1;
248:             $option['label'] = $option['value'] = $value;
249:             $options[] = $option;
250:         }
251: 
252:         return $options;
253:     }
254: 
255:     /**
256:      * Get the default element configuration
257:      *
258:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
259:      * @return  array
260:      */
261:     public static function getDefaultConfig($key = null)
262:     {
263:         $config = apply_filters('quform_default_config_select', array(
264:             // Basic
265:             'label' => __('Untitled', 'quform'),
266:             'options' => self::getDefaultOptions(),
267:             'nextOptionId' => 4,
268:             'defaultValue' => '',
269:             'customiseValues' => false,
270:             'noneOption' => true,
271:             'description' => '',
272:             'descriptionAbove' => '',
273:             'required' => false,
274: 
275:             // Styles
276:             'labelIcon' => '',
277:             'fieldSize' => 'inherit',
278:             'fieldWidth' => 'inherit',
279:             'fieldWidthCustom' => '',
280:             'enhancedSelectEnabled' => false,
281:             'enhancedSelectSearch' => true,
282:             'customClass' => '',
283:             'customElementClass' => '',
284:             'styles' => array(),
285: 
286:             // Labels
287:             'subLabel' => '',
288:             'subLabelAbove' => '',
289:             'adminLabel' => '',
290:             'tooltip' => '',
291:             'tooltipType' => 'icon',
292:             'tooltipEvent' => 'inherit',
293:             'labelPosition' => 'inherit',
294:             'labelWidth' => '',
295: 
296:             // Logic
297:             'logicEnabled' => false,
298:             'logicAction' => true,
299:             'logicMatch' => 'all',
300:             'logicRules' => array(),
301: 
302:             // Data
303:             'inArrayValidator' => true,
304:             'dynamicDefaultValue' => false,
305:             'dynamicKey' => '',
306:             'autocomplete' => '',
307:             'submitOnChoice' => false,
308:             'showInEmail' => true,
309:             'saveToDatabase' => true,
310: 
311:             // Advanced
312:             'visibility' => '',
313:             'validators' => array(),
314: 
315:             // Translations
316:             'messageRequired' => '',
317:             'noneOptionText' => '',
318:             'enhancedSelectNoResultsFound' => ''
319:         ));
320: 
321:         $config['type'] = 'select';
322: 
323:         if (Quform::isNonEmptyString($key)) {
324:             return Quform::get($config, $key);
325:         }
326: 
327:         return $config;
328:     }
329: }
330: 
API documentation generated by ApiGen