| | |
| | | } |
| | | protected static function buildClasses(array $config): string |
| | | { |
| | | $classes = ['field field-' . ($config['type'] ?? 'text')]; |
| | | $classes = ['field '. (str_replace('_','-',sanitize_text_field($config['type'] ?? 'text')))]; |
| | | if (!empty($config['required'])) { |
| | | $classes[] = 'required'; |
| | | } |
| | |
| | | protected static function handleCustomDatasets($config):string |
| | | { |
| | | if (array_key_exists('data', $config) && !empty($config['data'])) { |
| | | $datasets = array_map(function ($key) use ($config) { |
| | | $datasets = array_map(function ($value, $key) use ($config) { |
| | | $name = str_replace('_', '-', sanitize_title($key)); |
| | | return ' data-'.$name.'="'.$config['data'][$key].'"'; |
| | | }, $config['data']); |
| | | return ' data-'.$name.'="'.$value.'"'; |
| | | }, array_values($config['data']), array_keys($config['data'])); |
| | | |
| | | return implode($datasets); |
| | | } |
| | |
| | | } |
| | | $config['data']['upload-field'] = ''; |
| | | $config['data']['type'] = $config['multiple'] ? 'gallery' : 'single'; |
| | | $plural = 'images'; |
| | | $singular = 'image'; |
| | | if (!empty($config['content'])) { |
| | | $config['data']['content'] = $config['content']; |
| | | $content = $config['content']; |
| | | |
| | | $config['data']['content'] = $content; |
| | | $plural = |
| | | JVB_CONTENT[$content]['plural'] |
| | | ?? JVB_TAXONOMY[$content]['plural'] |
| | | ?? JVB_USER[$content]['plural'] |
| | | ?? str_replace('_', ' ', $content) . 's'; |
| | | |
| | | $singular = JVB_CONTENT[$content]['singular'] |
| | | ?? JVB_TAXONOMY[$content]['singular'] |
| | | ?? JVB_USER[$content]['singular'] |
| | | ?? str_replace('_', ' ',$config['content']); |
| | | } |
| | | if ($config['limit'] > 0) { |
| | | $config['data']['limit'] = $config['limit']; |
| | |
| | | <input type="file" |
| | | %s |
| | | accept="%s" |
| | | data-max-size="%s"> |
| | | data-max-size="%s" |
| | | data-ignore> |
| | | <h2>%s</h2> |
| | | %s |
| | | <p class="file-upload-text"> |
| | |
| | | esc_html(static::getAcceptedTypesLabel($config)), |
| | | esc_html(static::formatFileSize(static::getMaxFileSize($config))) |
| | | ); |
| | | $plural = (array_key_exists($config['content'], JVB_CONTENT)) ? JVB_CONTENT[$config['content']]['plural'] : (array_key_exists($config['content'], JVB_TAXONOMY) ? JVB_TAXONOMY[$config['content']]['plural'] : str_replace('_', ' ',$config['content']).'s'); |
| | | $singular = (array_key_exists($config['content'], JVB_CONTENT)) ? JVB_CONTENT[$config['content']]['singular'] : (array_key_exists($config['content'], JVB_TAXONOMY) ? JVB_TAXONOMY[$config['content']]['singular'] : str_replace('_', ' ',$config['content'])); |
| | | |
| | | |
| | | if ($config['destination'] === 'post_group') { |
| | | $input .= sprintf( |
| | | '<p class="hint">You can group images to create separate %s.</p> |
| | |
| | | ] |
| | | ]; |
| | | |
| | | $out .= static::render('image_data', $fields); |
| | | $out .= static::render('image_data', '', $fields); |
| | | $out .= static::renderUploadItemMetaEnd(); |
| | | |
| | | if ($additionalFields) { |
| | |
| | | ] |
| | | ]; |
| | | |
| | | $out .= static::render('image_data', $fields); |
| | | $out .= static::render('image_data', '', $fields); |
| | | $out .= static::renderUploadItemMetaEnd(); |
| | | |
| | | if ($additionalFields) { |
| | |
| | | ] |
| | | ]; |
| | | |
| | | $out .= static::render('image_data', $fields); |
| | | $out .= static::render('image_data', '', $fields); |
| | | |
| | | $out .= static::renderUploadItemMetaEnd(); |
| | | if ($additionalFields) { |
| | |
| | | $input .= static::render($newName, '', $fieldConfig); |
| | | } |
| | | $input .= sprintf( |
| | | '<button type="button" class="button add-tag-item">%s<span>%s</span></button></div>', |
| | | '<button type="button" class="button add-tag">%s<span>%s</span></button></div>', |
| | | jvbIcon('plus'), |
| | | $field['add_label']??'Add' |
| | | ); |
| | | |
| | | //Tag Display |
| | | $input .= '<div class="tag-items">'.static::renderTagItem($config['fields'], $value, $name, null, $tagFormat).'</div>'; |
| | | $input .= '<div class="tag-items">'.static::renderTagItems($config['fields'], $value, $name, $tagFormat).'</div>'; |
| | | |
| | | //Template for tags |
| | | $input .= sprintf( |
| | | '<template class="%s">%s</template>', |
| | | uniqid('tagListItem'), |
| | | static::renderTagItem($config['fields'], [], null, $name, $tagFormat) |
| | | static::renderTagItem($config['fields'], [], $name, null, $tagFormat) |
| | | ); |
| | | $input .= '</div>'; |
| | | |
| | | unset($config['label']); |
| | | |
| | | return static::fieldWrap($name, $input, $config); |
| | | } |
| | | protected static function renderTagItems(array $fields, mixed $value, string $name, string $tagFormat):string |
| | | { |
| | | if ($value === '') { |
| | | return ''; |
| | | } |
| | | if (is_string($value)) { |
| | | $value = explode(',', $value); |
| | | } |
| | | if (empty($value)) { |
| | | return ''; |
| | | } |
| | | $out = ''; |
| | | foreach ($value as $index => $v) { |
| | | $out .= static::renderTagItem($fields, $v, $name, $index, $tagFormat); |
| | | } |
| | | return $out; |
| | | |
| | | } |
| | | protected static function renderTagItem(array $fields, mixed $values, string $name, ?int $index, string $tagFormat):string |
| | | { |
| | | $tagText = static::getTagDisplayText($fields, $values, $tagFormat); |
| | |
| | | '<input type="hidden" |
| | | name="%s" |
| | | value="%s" |
| | | data-field="%s", |
| | | data-field="%s" |
| | | data-field-type="%s" />', |
| | | esc_attr($fullName), |
| | | esc_attr($value), |
| | |
| | | ); |
| | | |
| | | $out .= sprintf( |
| | | '<button type="button" class="remove-tag" aria-label="Remove">%s</button></div>', |
| | | '<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 |
| | |
| | | protected static function renderGroup(string $name, mixed $value, array $config): string |
| | | { |
| | | $fields = $config['fields'] ?? []; |
| | | error_log('Group fields: '.print_r($fields, true)); |
| | | $values = is_array($value) ? $value : []; |
| | | |
| | | $wrapper = (array_key_exists('wrap', $config)) ? 'details' : 'fieldset'; |