| | |
| | | '<div class="%s" data-field="%s" data-field-type="%s"%s>', |
| | | $classes, |
| | | $name, |
| | | $config['type'], |
| | | str_replace('_', '-', $config['type']), |
| | | $datasets |
| | | ); |
| | | |
| | | $output .= static::buildCharacterLimit($config); |
| | | $output .= static::buildLabel($name, $config); |
| | | if (!array_key_exists('skipInput', $config)) { |
| | | $output .= static::buildInput($content); |
| | |
| | | ); |
| | | } |
| | | |
| | | protected static function buildCharacterLimit(array $config): string |
| | | { |
| | | $type = $config['type'] ?? 'text'; |
| | | if (in_array($type, ['upload', 'gallery', 'selector'])) { |
| | | return ''; |
| | | } |
| | | if (empty($config['maxlength'])) { |
| | | return ''; |
| | | } |
| | | return sprintf( |
| | | '<span class="char-limit"><span class="current">0</span> / <span class="limit">%s</span></span>', |
| | | esc_html($config['maxlength']) |
| | | ); |
| | | } |
| | | |
| | | protected static function buildLabel(string $name, array $config):string |
| | | { |
| | | if (!empty($config['label'])) { |
| | |
| | | return ''; |
| | | } |
| | | |
| | | protected static function buildInput(string $content):string |
| | | public static function buildInput(string $content):string |
| | | { |
| | | return sprintf( |
| | | '<div class="field-input-wrapper"> |
| | |
| | | |
| | | protected static function renderText(string $name, mixed $value, array $config): string |
| | | { |
| | | $value = ($value === '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $value = ($value !== '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $input = sprintf( |
| | | '<input type="%s"%s%s />', |
| | | $config['subtype']??'text', |
| | |
| | | { |
| | | $attrs = static::inputAttrs($name, $config); |
| | | |
| | | $value = ($value === '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $value = ($value !== '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $input = sprintf( |
| | | '<input type="number"%s%s />', |
| | | $value, |
| | |
| | | |
| | | $attrs = static::inputAttrs($name, $config); |
| | | |
| | | $value = ($value === '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $value = ($value !== '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $input = sprintf( |
| | | '<div class="quantity"> |
| | | <button type="button" class="decrease" title="%s" aria-label="Decrease %s">%s</button> |
| | |
| | | protected static function renderEmail(string $name, mixed $value, array $config): string |
| | | { |
| | | $config['validate'] = 'email'; |
| | | $value = ($value === '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $value = ($value !== '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $input = sprintf( |
| | | '<input type="email"%s%s />', |
| | | $value, |
| | |
| | | protected static function renderUrl(string $name, mixed $value, array $config): string |
| | | { |
| | | $config['validate'] = 'url'; |
| | | $value = ($value === '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $value = ($value !== '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $input = sprintf( |
| | | '<input type="url"%s%s />', |
| | | $value, |
| | |
| | | protected static function renderTel(string $name, mixed $value, array $config): string |
| | | { |
| | | $config['validate'] = 'phone'; |
| | | $value = ($value === '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $value = ($value !== '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $input = sprintf( |
| | | '<input type="tel"%s%s />', |
| | | $value, |
| | |
| | | } |
| | | } |
| | | |
| | | $value = ($value === '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $value = ($value !== '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $input = sprintf( |
| | | '<input type="date"%s%s />', |
| | | $value, |
| | |
| | | |
| | | protected static function renderTime(string $name, mixed $value, array $config): string |
| | | { |
| | | $value = ($value === '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $value = ($value !== '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $input = sprintf( |
| | | '<input type="time"%s%s />', |
| | | $value, |
| | |
| | | |
| | | protected static function renderDatetime(string $name, mixed $value, array $config): string |
| | | { |
| | | $value = ($value === '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $value = ($value !== '') ? ' value="'.esc_attr($value).'"' : ''; |
| | | $input = sprintf( |
| | | '<input type="datetime-local"%s%s />', |
| | | $value, |
| | |
| | | $optionsHtml = ''; |
| | | if (empty($config['required'])) { |
| | | $optionsHtml .= '<option value="">— Select —</option>'; |
| | | } else { |
| | | $optionsHtml .= '<option value="" disabled selected hidden>— Select —</option>'; |
| | | } |
| | | |
| | | foreach ($options as $optValue => $optLabel) { |
| | | $optionsHtml .= sprintf( |
| | | '<option value="%s"%s>%s</option>', |
| | | esc_attr($optValue), |
| | | selected($value, $optValue), |
| | | selected($value, $optValue, false), |
| | | esc_html($optLabel) |
| | | ); |
| | | } |
| | |
| | | $optValue, |
| | | esc_attr($optValue), |
| | | $checked, |
| | | $name, |
| | | esc_attr($name), |
| | | $optValue, |
| | | esc_html($optLabel) |
| | | ); |
| | |
| | | foreach ($options as $optValue => $optLabel) { |
| | | $radios .= sprintf( |
| | | ' |
| | | <input type="radio" name="%s" value="%s"%s /> |
| | | <input type="radio" name="%s" id="%s-%s" value="%s"%s /> |
| | | <label class="radio-option" for="%s-%s"> |
| | | <span>%s</span> |
| | | </label>', |
| | | esc_attr($name), |
| | | esc_attr($name), |
| | | $optValue, |
| | | esc_attr($optValue), |
| | | checked($value, $optValue), |
| | | $name, |
| | | checked($value, $optValue,false), |
| | | esc_attr($name), |
| | | $optValue, |
| | | esc_html($optLabel) |
| | | ); |
| | |
| | | ?? str_replace('_', ' ',$config['content']); |
| | | } |
| | | if ($config['limit'] > 0) { |
| | | $config['data']['limit'] = $config['limit']; |
| | | $config['data']['max-files'] = $config['limit']; |
| | | } |
| | | |
| | | $attachmentIds = static::parseIds($value); |
| | |
| | | |
| | | $input .= '<div class="file-error"></div>'; |
| | | $input .= jvbRenderProgressBar('', false, true, true); |
| | | $input .= '</div>'; |
| | | |
| | | $input .= '</div>'; // closes .file-upload-wrapper |
| | | |
| | | if ($config['destination'] === 'post_group') { |
| | | $input .= static::renderUploadGroupAreaStart($config, $plural, $singular); |
| | |
| | | $input .= static::renderUploadGroupAreaEnd($config, $plural, $singular); |
| | | } |
| | | |
| | | $input .= '</div>'; // closes .file-upload-container |
| | | unset($config['description']); |
| | | unset($config['label']); |
| | | return static::fieldWrap($name, $input, $config); |
| | |
| | | $input .= sprintf( |
| | | '<button type="button" class="button add-tag">%s<span>%s</span></button></div>', |
| | | jvbIcon('plus'), |
| | | $field['add_label']??'Add' |
| | | $config['add_label']??'Add' |
| | | ); |
| | | |
| | | //Tag Display |
| | |
| | | } |
| | | protected static function renderTagItems(array $fields, mixed $value, string $name, string $tagFormat):string |
| | | { |
| | | if ($value === '') { |
| | | if (!$value || $value === '') { |
| | | return ''; |
| | | } |
| | | if (is_string($value)) { |
| | |
| | | |
| | | $out = sprintf( |
| | | '<div class="tag-item"%s><span class="tag-label">%s</span>', |
| | | ($index) ? ' data-index="'.$index.'"' : '', |
| | | ($index !== null) ? ' data-index="'.$index.'"' : '', |
| | | $tagText |
| | | ); |
| | | |
| | | foreach ($fields as $fieldName => $fieldConfig) { |
| | | $value = $values[$fieldName]??''; |
| | | $fullName = (!$index) ? $fieldName : sprintf('%s:%s:%s', $name, $index, $fieldName); |
| | | $fullName = ($index === null) ? $fieldName : sprintf('%s:%s:%s', $name, $index, $fieldName); |
| | | |
| | | $out .= sprintf( |
| | | '<input type="hidden" |
| | | name="%s" |
| | | value="%s" |
| | | data-field="%s" |
| | | data-field-type="%s" />', |
| | | name="%s" |
| | | value="%s" |
| | | data-field="%s" |
| | | data-field-type="%s" |
| | | id="%s" />', |
| | | esc_attr($fullName), |
| | | esc_attr($value), |
| | | esc_attr($fieldName), |
| | | esc_attr($fieldConfig['type']) |
| | | ); |
| | | |
| | | $out .= sprintf( |
| | | '<button type="button" class="remove-tag" aria-label="Remove">%s</button>', |
| | | jvbIcon('x') |
| | | esc_attr($fieldConfig['type']), |
| | | esc_attr($fullName) |
| | | ); |
| | | } |
| | | |
| | | $out .= sprintf( |
| | | '<button type="button" class="remove-tag" aria-label="Remove">%s</button>', |
| | | jvbIcon('x') |
| | | ); |
| | | $out .='</div>'; |
| | | return $out; |
| | | } |
| | | protected static function getTagDisplayText(array $fields, mixed $values, string $tagFormat):string |
| | | { |
| | | if (empty($data)) { |
| | | if (empty($values)) { |
| | | return 'New Item'; |
| | | } |
| | | |
| | |
| | | $firstKey = array_key_first($fields); |
| | | return $values[$firstKey] ?? 'New Item'; |
| | | case 'all_fields': |
| | | $values = array_filter(array_values($data)); |
| | | $values = array_filter(array_values($values)); |
| | | return implode(', ', $values) ?: 'New Item'; |
| | | default: |
| | | if (strpos($tagFormat, '{') !== false) { |
| | |
| | | |
| | | foreach ($fields as $fieldName => $fieldConfig) { |
| | | $fieldValue = $values[$fieldName] ?? ''; |
| | | $fullName = "{$name}:{$fieldName}"; |
| | | $fullName = array_key_exists('wrap', $config) ? $fieldName : "{$name}:{$fieldName}"; |
| | | $output .= static::render($fullName, $fieldValue, $fieldConfig); |
| | | } |
| | | |
| | | $output .= sprintf('</%s>', esc_attr($wrapper)); |
| | | |
| | | unset($config['label']); |
| | | return static::fieldWrap($name, $output, $config); |
| | | } |
| | | |