| | |
| | | } |
| | | 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'; |
| | | } |
| | |
| | | $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 |