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_Radio extends Quform_Element_Multi implements Quform_Element_Editable
  7: {
  8:     /**
  9:      * Get the HTML for the element label
 10:      *
 11:      * @param   array        $context
 12:      * @param   string|bool  $forAttribute  Set the "for" attribute to the element unique ID
 13:      * @param   bool         $id            Add a unique ID to the label
 14:      * @return  string
 15:      */
 16:     protected function getLabelHtml(array $context = array(), $forAttribute = true, $id = false)
 17:     {
 18:         return parent::getLabelHtml($context, false, true);
 19:     }
 20: 
 21:     /**
 22:      * Get the HTML attributes for the field
 23:      *
 24:      * @param   array  $option   The current option within the loop
 25:      * @param   array  $context
 26:      * @return  array
 27:      */
 28:     protected function getFieldAttributes(array $option, array $context = array())
 29:     {
 30:         $attributes = array(
 31:             'type' => 'radio',
 32:             'name' => $this->getFullyQualifiedName(),
 33:             'id' => sprintf('%s_%d', $this->getUniqueId(), $this->getOptionValue($option, 'id')),
 34:             'class' => Quform::sanitizeClass($this->getFieldClasses($option, $context)),
 35:             'value' => $this->getOptionValue($option, 'value')
 36:         );
 37: 
 38:         if ($this->hasValue($attributes['value'])) {
 39:             $attributes['checked'] = true;
 40:         }
 41: 
 42:         $attributes = apply_filters('quform_field_attributes', $attributes, $this, $this->form, $context, $option);
 43:         $attributes = apply_filters('quform_field_attributes_' . $this->getIdentifier(), $attributes, $this, $this->form, $context, $option);
 44: 
 45:         return $attributes;
 46:     }
 47: 
 48:     /**
 49:      * Get the classes for the field
 50:      *
 51:      * @param   array  $option  The current option within the loop
 52:      * @param   array  $context
 53:      * @return  array
 54:      */
 55:     protected function getFieldClasses(array $option,  array $context = array())
 56:     {
 57:         $classes = array(
 58:             'quform-field',
 59:             'quform-field-radio',
 60:             sprintf('quform-field-%s', $this->getIdentifier()),
 61:             sprintf('quform-field-%s_%d', $this->getIdentifier(), $this->getOptionValue($option, 'id'))
 62:         );
 63: 
 64:         if (Quform::isNonEmptyString($this->config('customClass'))) {
 65:             $classes[] = $this->config('customClass');
 66:         }
 67: 
 68:         if ($this->config('submitOnChoice')) {
 69:             $classes[] = 'quform-submit-on-choice';
 70:         }
 71: 
 72:         $classes = apply_filters('quform_field_classes', $classes, $option, $this, $this->form, $context);
 73:         $classes = apply_filters('quform_field_classes_' . $this->getIdentifier(), $classes, $option, $this, $this->form, $context);
 74: 
 75:         return $classes;
 76:     }
 77: 
 78:     /**
 79:      * Get the HTML for the field
 80:      *
 81:      * @param   array   $context
 82:      * @return  string
 83:      */
 84:     protected function getFieldHtml(array $context = array())
 85:     {
 86:         $output = '';
 87: 
 88:         foreach ($this->getOptions() as $option) {
 89:             $attributes = $this->getFieldAttributes($option, $context);
 90: 
 91:             $output .= sprintf(
 92:                 '<div class="quform-option%s">',
 93:                 Quform::isNonEmptyString($this->getOptionValue($option, 'label')) ? '' : ' quform-option-label-empty'
 94:             );
 95: 
 96:             $output .= Quform::getHtmlTag('input', $attributes);
 97: 
 98:             $output .= sprintf(
 99:                 '<label for="%s" class="quform-option-label quform-option-label-%s_%d">',
100:                 esc_attr($attributes['id']),
101:                 esc_attr($this->getIdentifier()),
102:                 $this->getOptionValue($option, 'id')
103:             );
104: 
105:             if (Quform::isNonEmptyString($this->getOptionValue($option, 'icon'))) {
106:                 $output .= sprintf('<span class="quform-option-icon"><i class="%s"></i></span>', Quform::escape($this->getOptionValue($option, 'icon')));
107:             }
108: 
109:             if (Quform::isNonEmptyString($this->getOptionValue($option, 'iconSelected'))) {
110:                 $output .= sprintf('<span class="quform-option-icon-selected"><i class="%s"></i></span>', Quform::escape($this->getOptionValue($option, 'iconSelected')));
111:             }
112: 
113:             if (Quform::isNonEmptyString($this->getOptionValue($option, 'label'))) {
114:                 $output .= sprintf('<span class="quform-option-text">%s</span>', do_shortcode($this->getOptionValue($option, 'label')));
115:             }
116: 
117:             $output .= '</label>';
118: 
119:             $output .= '</div>';
120:         }
121: 
122:         return $output;
123:     }
124: 
125:     /**
126:      * Get the HTML for the element input wrapper
127:      *
128:      * @param   array   $context
129:      * @return  string
130:      */
131:     protected function getInputHtml(array $context = array())
132:     {
133:         $output = sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getInputClasses($context))));
134: 
135:         $optionsClasses = array('quform-options', 'quform-cf');
136: 
137:         if (is_numeric($this->config('optionsLayout'))) {
138:             $optionsClasses[] = 'quform-options-columns';
139:             $optionsClasses[] = sprintf('quform-%d-columns', $this->config('optionsLayout'));
140: 
141:             if (Quform::isNonEmptyString($this->config('optionsLayoutResponsiveColumns')) && $this->config('optionsLayoutResponsiveColumns') != 'custom') {
142:                 $optionsClasses[] = sprintf('quform-responsive-columns-%s', $this->config('optionsLayoutResponsiveColumns'));
143:             }
144:         } else {
145:             $optionsClasses[] = sprintf('quform-options-%s', $this->config('optionsLayout'));
146:         }
147: 
148:         if (Quform::isNonEmptyString($context['optionsStyle'])) {
149:             $optionsClasses[] = sprintf('quform-options-style-%s', $context['optionsStyle']);
150: 
151:             if ($context['optionsStyle'] == 'button') {
152:                 if (Quform::isNonEmptyString($context['optionsButtonStyle'])) {
153:                     $optionsClasses[] = sprintf('quform-button-style-%s', $context['optionsButtonStyle']);
154:                 }
155: 
156:                 if (Quform::isNonEmptyString($context['optionsButtonSize'])) {
157:                     $optionsClasses[] = sprintf('quform-button-size-%s', $context['optionsButtonSize']);
158:                 }
159: 
160:                 if (Quform::isNonEmptyString($context['optionsButtonWidth']) && $context['optionsButtonWidth'] != 'custom') {
161:                     $optionsClasses[] = sprintf('quform-button-width-%s', $context['optionsButtonWidth']);
162:                 }
163: 
164:                 if (Quform::isNonEmptyString($context['optionsButtonIconPosition'])) {
165:                     $optionsClasses[] = sprintf('quform-button-icon-%s', $context['optionsButtonIconPosition']);
166:                 }
167:             }
168:         }
169: 
170:         if ($this->hasOnlySimpleOptions($context)) {
171:             $optionsClasses[] = 'quform-options-simple';
172:         }
173: 
174:         $output .= sprintf(
175:             '<div class="%s"%s>',
176:             Quform::escape(Quform::sanitizeClass($optionsClasses)),
177:             Quform::isNonEmptyString($this->config('label')) ? ' role="radiogroup" aria-labelledby="' . Quform::escape($this->getUniqueId() . '_label') . '"' : ''
178:         );
179: 
180:         $output .= $this->getFieldHtml();
181: 
182:         $output .= '</div></div>';
183: 
184:         return $output;
185:     }
186: 
187:     /**
188:      * Returns true if the options are simple text options, false otherwise
189:      *
190:      * @param   array  $context
191:      * @return  bool
192:      */
193:     protected function hasOnlySimpleOptions(array $context = array())
194:     {
195:         if (Quform::isNonEmptyString($context['optionsStyle'])) {
196:             return false;
197:         }
198: 
199:         $keys = array('image', 'imageSelected', 'width', 'height', 'icon', 'iconSelected');
200: 
201:         foreach ($this->getOptions() as $option) {
202:             foreach ($keys as $key) {
203:                 if (Quform::isNonEmptyString($this->getOptionValue($option, $key))) {
204:                     return false;
205:                 }
206:             }
207:         }
208: 
209:         return true;
210:     }
211: 
212:     /**
213:      * Get the field HTML when editing
214:      *
215:      * @return string
216:      */
217:     public function getEditFieldHtml()
218:     {
219:         return $this->getFieldHtml();
220:     }
221: 
222:     /**
223:      * Render the CSS for this element
224:      *
225:      * @param   array   $context
226:      * @return  string
227:      */
228:     protected function renderCss(array $context = array())
229:     {
230:         $css = parent::renderCss($context);
231: 
232:         if ($this->config('optionsLayoutResponsiveColumns') == 'custom' && Quform::isNonEmptyString($this->config('optionsLayoutResponsiveColumnsCustom'))) {
233:             $css .= sprintf(
234:                 '@media (max-width: %s) { .quform-input-%s > .quform-options-columns > .quform-option { float: none; width: 100%% !important; } }',
235:                 Quform::addCssUnit($this->config('optionsLayoutResponsiveColumnsCustom')),
236:                 $this->getIdentifier()
237:             );
238:         }
239: 
240:         if ($context['optionsButtonWidth'] == 'custom' && Quform::isNonEmptyString($context['optionsButtonWidthCustom'])) {
241:             $css .= sprintf(
242:                 '.quform-input-%s .quform-option .quform-option-label { width: %s;}',
243:                 $this->getIdentifier(),
244:                 Quform::addCssUnit($context['optionsButtonWidthCustom'])
245:             );
246:         }
247: 
248:         foreach ($this->getOptions() as $option) {
249:             if (Quform::isNonEmptyString($this->getOptionValue($option, 'image'))) {
250:                 $css .= sprintf(
251:                     '.quform-option-label-%s_%d { background-image: url(%s); }',
252:                     $this->getIdentifier(),
253:                     $this->getOptionValue($option, 'id'),
254:                     esc_url($this->getOptionValue($option, 'image'))
255:                 );
256:             }
257: 
258:             if (Quform::isNonEmptyString($this->getOptionValue($option, 'imageSelected'))) {
259:                 $css .= sprintf(
260:                     '.quform-field-radio:checked + .quform-option-label-%s_%d { background-image: url(%s); }',
261:                     $this->getIdentifier(),
262:                     $this->getOptionValue($option, 'id'),
263:                     esc_url($this->getOptionValue($option, 'imageSelected'))
264:                 );
265:             }
266: 
267:             if (Quform::isNonEmptyString($this->getOptionValue($option, 'width'))) {
268:                 $css .= sprintf(
269:                     '.quform-option .quform-option-label-%s_%d { width: %s; }',
270:                     $this->getIdentifier(),
271:                     $this->getOptionValue($option, 'id'),
272:                     Quform::addCssUnit($this->getOptionValue($option, 'width'))
273:                 );
274:             }
275: 
276:             if (Quform::isNonEmptyString($this->getOptionValue($option, 'height'))) {
277:                 $css .= sprintf(
278:                     '.quform-option .quform-option-label-%s_%d { height: %s; }',
279:                     $this->getIdentifier(),
280:                     $this->getOptionValue($option, 'id'),
281:                     Quform::addCssUnit($this->getOptionValue($option, 'height'))
282:                 );
283:             }
284:         }
285: 
286:         return $css;
287:     }
288: 
289:     /**
290:      * Get the default option config
291:      *
292:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
293:      * @return  array
294:      */
295:     public static function getDefaultOptionConfig($key = null)
296:     {
297:         $config = array(
298:             'label' => '',
299:             'value' => '',
300:             'image' => '',
301:             'imageSelected' => '',
302:             'width' => '',
303:             'height' => '',
304:             'icon' => '',
305:             'iconSelected' => ''
306:         );
307: 
308:         if (Quform::isNonEmptyString($key)) {
309:             return Quform::get($config, $key);
310:         }
311: 
312:         return $config;
313:     }
314: 
315:     /**
316:      * Get the default options for this element
317:      *
318:      * @return array
319:      */
320:     protected static function getDefaultOptions()
321:     {
322:         $options = array();
323:         $defaults = array(__('Option 1', 'quform'), __('Option 2', 'quform'), __('Option 3', 'quform'));
324: 
325:         foreach ($defaults as $key => $value) {
326:             $option = self::getDefaultOptionConfig();
327:             $option['id'] = $key + 1;
328:             $option['label'] = $option['value'] = $value;
329:             $options[] = $option;
330:         }
331: 
332:         return $options;
333:     }
334: 
335:     /**
336:      * Get the default element configuration
337:      *
338:      * @param   string|null  $key  Get the config by key, if omitted the full config is returned
339:      * @return  array
340:      */
341:     public static function getDefaultConfig($key = null)
342:     {
343:         $config = apply_filters('quform_default_config_radio', array(
344:             // Basic
345:             'label' => __('Untitled', 'quform'),
346:             'options' => self::getDefaultOptions(),
347:             'nextOptionId' => 4,
348:             'defaultValue' => '',
349:             'customiseValues' => false,
350:             'description' => '',
351:             'descriptionAbove' => '',
352:             'required' => false,
353: 
354:             // Styles
355:             'labelIcon' => '',
356:             'optionsLayout' => 'block',
357:             'optionsLayoutResponsiveColumns' => 'phone-landscape',
358:             'optionsLayoutResponsiveColumnsCustom' => '',
359:             'optionsStyle' => 'inherit',
360:             'optionsButtonStyle' => 'inherit',
361:             'optionsButtonSize' => 'inherit',
362:             'optionsButtonWidth' => 'inherit',
363:             'optionsButtonWidthCustom' => '',
364:             'optionsButtonIconPosition' => 'inherit',
365:             'customClass' => '',
366:             'customElementClass' => '',
367:             'styles' => array(),
368: 
369:             // Labels
370:             'subLabel' => '',
371:             'subLabelAbove' => '',
372:             'adminLabel' => '',
373:             'tooltip' => '',
374:             'tooltipType' => 'icon',
375:             'tooltipEvent' => 'inherit',
376:             'labelPosition' => 'inherit',
377:             'labelWidth' => '',
378: 
379:             // Logic
380:             'logicEnabled' => false,
381:             'logicAction' => true,
382:             'logicMatch' => 'all',
383:             'logicRules' => array(),
384: 
385:             // Data
386:             'inArrayValidator' => true,
387:             'dynamicDefaultValue' => false,
388:             'dynamicKey' => '',
389:             'submitOnChoice' => false,
390:             'showInEmail' => true,
391:             'saveToDatabase' => true,
392: 
393:             // Advanced
394:             'visibility' => '',
395:             'validators' => array(),
396: 
397:             // Translations
398:             'messageRequired' => ''
399:         ));
400: 
401:         $config['type'] = 'radio';
402: 
403:         if (Quform::isNonEmptyString($key)) {
404:             return Quform::get($config, $key);
405:         }
406: 
407:         return $config;
408:     }
409: }
410: 
API documentation generated by ApiGen