| | |
| | | $output .= static::buildLabel($name, $config); |
| | | if (!array_key_exists('skipInput', $config)) { |
| | | $output .= static::buildInput($content); |
| | | } else { |
| | | $output .= $content; |
| | | } |
| | | |
| | | $output .= static::buildHint($config); |
| | |
| | | |
| | | protected static function renderRadio(string $name, mixed $value, array $config): string |
| | | { |
| | | $options = $config['options'] ?? []; |
| | | $options = $config['options'] ?? []; |
| | | $inputClass = !empty($config['inputClass']) ? ' class="' . esc_attr($config['inputClass']) . '"' : ''; |
| | | $idPrefix = $config['idPrefix'] ?? ''; |
| | | |
| | | $radios = sprintf( |
| | | '<fieldset> |
| | | <legend>%s%s</legend>', |
| | | <legend>%s%s</legend>', |
| | | array_key_exists('label', $config) ? esc_html($config['label']) : 'Select an option', |
| | | array_key_exists('required', $config) && $config['required']===true ? '<span class="required" aria-label="required">*</span>' : '' |
| | | array_key_exists('required', $config) && $config['required'] === true |
| | | ? '<span class="required" aria-label="required">*</span>' : '' |
| | | ); |
| | | |
| | | foreach ($options as $optValue => $optLabel) { |
| | | foreach ($options as $optValue => $optConfig) { |
| | | if (is_array($optConfig)) { |
| | | $optLabel = $optConfig['label'] ?? $optValue; |
| | | $optIcon = $optConfig['icon'] ?? null; |
| | | $optDisabled = !empty($optConfig['disabled']) ? ' disabled' : ''; |
| | | } else { |
| | | $optLabel = $optConfig; |
| | | $optIcon = null; |
| | | $optDisabled = ''; |
| | | } |
| | | |
| | | $labelContent = $optIcon |
| | | ? jvbDashIcon($optIcon) |
| | | : '<span>' . esc_html($optLabel) . '</span>'; |
| | | |
| | | $optId = esc_attr($idPrefix . $name . '-' . $optValue); |
| | | |
| | | $radios .= sprintf( |
| | | ' |
| | | <input type="radio" name="%s" id="%s-%s" value="%s"%s /> |
| | | <label class="radio-option" for="%s-%s"> |
| | | <span>%s</span> |
| | | </label>', |
| | | '<input type="radio" name="%s" id="%s" value="%s"%s%s%s /> |
| | | <label class="radio-option" for="%s" title="%s">%s</label>', |
| | | esc_attr($name), |
| | | esc_attr($name), |
| | | $optValue, |
| | | $optId, |
| | | esc_attr($optValue), |
| | | checked($value, $optValue,false), |
| | | esc_attr($name), |
| | | $optValue, |
| | | esc_html($optLabel) |
| | | checked($value, $optValue, false), |
| | | $optDisabled, |
| | | $inputClass, |
| | | $optId, |
| | | esc_html($optLabel), |
| | | $labelContent |
| | | ); |
| | | } |
| | | |
| | |
| | | } |
| | | $plural = static::getPlural($config); |
| | | $input .= sprintf( |
| | | '<div class="selected-item row" role="region" aria-label="Selected %s"></div>', |
| | | '<div class="selected-items row" role="region" aria-label="Selected %s"></div>', |
| | | $plural[1]??'' |
| | | ); |
| | | |
| | | $config['type'] = 'selector'; |
| | | unset($config['label']); |
| | | unset($config['description']); |
| | | unset($config['hint']); |
| | |
| | | $plural = $taxonomy->labels->name; |
| | | } |
| | | $attr = sprintf( |
| | | ' data-taxonomy="%s" data-single="%s" data-plural="%s', |
| | | ' data-taxonomy="%s" data-single="%s" data-plural="%s"', |
| | | $config['taxonomy'], |
| | | $single, |
| | | $plural |
| | |
| | | $plural = $postType->labels->name; |
| | | } |
| | | $attr = sprintf( |
| | | ' data-content="%s" data-single="%s" data-plural="%s', |
| | | ' data-content="%s" data-single="%s" data-plural="%s"', |
| | | $config['content'], |
| | | $single, |
| | | $plural |
| | |
| | | $plural = 'Users'; |
| | | } |
| | | $attr = sprintf( |
| | | ' data-user="%s" data-single="%s" data-plural="%s', |
| | | ' data-user="%s" data-single="%s" data-plural="%s"', |
| | | $config['user'], |
| | | $single, |
| | | $plural |
| | |
| | | $dataAttrs[] = 'data-selected="'.esc_attr(implode(',',$selected)).'"'; |
| | | } |
| | | if ($config['autocomplete']) { |
| | | $dataAttrs[] = 'autocomplete'; |
| | | $dataAttrs[] = 'data-autocomplete'; |
| | | } |
| | | if (array_key_exists('hidden', $config) && $config['hidden']) { |
| | | $dataAttrs[] = 'hidden'; |
| | |
| | | jvbIcon('plus-square') |
| | | ); |
| | | } |
| | | protected static function buildSelectorAutocomplete(string $name, array $config):string |
| | | { |
| | | return sprintf( |
| | | '<input type="hidden" id="%s-autocomplete" autocomplete="off" data-ignore data-autocomplete> |
| | | <p class="message" hidden aria-live="polite">{ <span>Loading items</span> }</p> |
| | | <div class="auto-wrapper" hidden><ul class="search-results"></ul><button class="submit-term" hidden data-ignore><strong>Create: </strong> "<span></span>"</button></div>', |
| | | $name |
| | | ); |
| | | } |
| | | protected static function buildSelectorAutocomplete(string $name, array $config): string |
| | | { |
| | | $containerId = sprintf('%s-%s-selector', $name, $config['subtype'] ?? $config['type']); |
| | | return sprintf( |
| | | '<input type="hidden" name="%s" value=""> |
| | | <input type="search" id="%s-autocomplete" autocomplete="off" data-ignore data-autocomplete> |
| | | <p class="message" hidden aria-live="polite">{ <span>Loading items</span> }</p> |
| | | <div class="auto-wrapper" hidden><ul class="search-results"></ul><button class="submit-term" hidden data-ignore><strong>Create: </strong> "<span></span>"</button></div>', |
| | | esc_attr($name), |
| | | esc_attr($name) |
| | | ); |
| | | } |
| | | |
| | | protected static function renderTaxonomy(string $name, mixed $value, array $config): string |
| | | { |