| | |
| | | return jvbRenderTermList($terms, $field['label']); |
| | | } |
| | | |
| | | protected function renderTagListField(string $name, array|bool $value, array $field): string |
| | | { |
| | | if (empty($value) || !is_array($value)) { |
| | | return ''; |
| | | } |
| | | |
| | | if (!isset($field['fields']) || !is_array($field['fields'])) { |
| | | return ''; |
| | | } |
| | | |
| | | $tag_format = $field['tag_format'] ?? 'first_field'; |
| | | $output = '<div class="tag-list-display">'; |
| | | |
| | | if (!empty($field['label']) && ($field['show_label'] ?? false)) { |
| | | $output .= '<h4 class="tag-list-label">' . esc_html($field['label']) . '</h4>'; |
| | | } |
| | | |
| | | $output .= '<div class="tag-list-items">'; |
| | | |
| | | foreach ($value as $item) { |
| | | if (!is_array($item) || empty($item)) { |
| | | continue; |
| | | } |
| | | |
| | | $tag_text = $this->getTagDisplayText($item, $tag_format); |
| | | $output .= '<span class="tag-list-item">' . esc_html($tag_text) . '</span>'; |
| | | } |
| | | |
| | | $output .= '</div></div>'; |
| | | |
| | | return $output; |
| | | } |
| | | |
| | | /** |
| | | * Get display text for a tag based on format |
| | | */ |
| | | protected function getTagDisplayText(array $data, string $format): string |
| | | { |
| | | $values = array_filter(array_values($data)); |
| | | |
| | | if (empty($values)) { |
| | | return ''; |
| | | } |
| | | |
| | | switch ($format) { |
| | | case 'first_field': |
| | | return $values[0]; |
| | | |
| | | case 'all_fields': |
| | | return implode(', ', $values); |
| | | |
| | | default: |
| | | // Template format like "{name} ({email})" |
| | | if (strpos($format, '{') !== false) { |
| | | $text = $format; |
| | | foreach ($data as $key => $value) { |
| | | $text = str_replace('{' . $key . '}', $value, $text); |
| | | } |
| | | return $text; |
| | | } |
| | | |
| | | // Use specific field |
| | | return $data[$format] ?? $values[0]; |
| | | } |
| | | } |
| | | |
| | | protected function renderRepeaterField($name, $value, $field):string |
| | | { |
| | | // jvbDump($value, 'Repeater Field:'); |