Skip to content

Commit 6303cfd

Browse files
committed
Updated link to new multi-text-groups
1 parent 80b8f75 commit 6303cfd

2 files changed

Lines changed: 13 additions & 138 deletions

File tree

dt-core/global-functions.php

Lines changed: 3 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ function render_field_for_display( $field_key, $fields, $post, $show_extra_contr
654654
case 'user_select':
655655
DT_Components::render_user_select( $field_key, $fields, $post, $params );
656656
break;
657+
case 'link':
658+
DT_Components::render_link( $field_key, $fields, $post, $params );
659+
break;
657660
default:
658661
$is_legacy = true;
659662
break;
@@ -663,60 +666,6 @@ function render_field_for_display( $field_key, $fields, $post, $show_extra_contr
663666
$is_empty_post = !is_array( $post ) || count( array_keys( $post ) ) <= 1; // if this is a new post, it only has a post_type key
664667
$hide_label = isset( $params['hide_label'] ) && $params['hide_label'] === true;
665668
?>
666-
<?php if ( !$hide_label || $field_type === 'link' ) : ?>
667-
<div class="section-subheader" <?php echo ( $hide_label && $field_type === 'link' ) ? 'style="display: flex; align-items: center; justify-content: flex-start;"' : ''; ?>>
668-
<?php if ( !$hide_label ) : ?>
669-
<?php dt_render_field_icon( $fields[$field_key] );
670-
671-
echo esc_html( $fields[$field_key]['name'] );
672-
?> <span id="<?php echo esc_html( $display_field_id ); ?>-spinner" class="loading-spinner"></span>
673-
<?php if ( $is_private ) : ?>
674-
<i class="fi-lock small" title="<?php _x( "Private Field: Only I can see it's content", 'disciple_tools' )?>"></i>
675-
<?php endif; ?>
676-
<?php endif; ?>
677-
678-
<?php if ( $field_type === 'link' ) : ?>
679-
<?php $only_one_option = count( $fields[$field_key]['default'] ) === 1 ? esc_attr( array_keys( $fields[$field_key]['default'] )[0] ) : '' ?>
680-
681-
<div class="add-link-dropdown"
682-
<?php echo !empty( $only_one_option ) ? 'data-only-one-option' : '' ?>
683-
data-link-type="<?php echo esc_attr( $only_one_option ) ?>"
684-
data-field-key="<?php echo esc_attr( $field_key ) ?>">
685-
<button
686-
class="add-button add-link-dropdown__button"
687-
type="button"
688-
data-field-type="<?php echo esc_html( $field_type ) ?>"
689-
data-list-class="<?php echo esc_html( $display_field_id ); ?>"
690-
<?php echo esc_html( $disabled ); ?>
691-
>
692-
<img src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/small-add.svg' ) ?>"/>
693-
</button>
694-
695-
<div class="add-link-dropdown__content add-link-<?php echo esc_attr( $display_field_id ) ?>"
696-
style="<?php echo count( $fields[$field_key]['default'] ) < 2 ? 'display: none' : '' ?>">
697-
<?php foreach ( $fields[$field_key]['default'] as $option_key => $option_value ): ?>
698-
699-
<?php if ( isset( $option_value['deleted'] ) && $option_value['deleted'] === true ) {
700-
continue;
701-
} ?>
702-
703-
<div
704-
class="add-link__option"
705-
<?php echo !empty( $only_one_option ) ? 'data-only-one-option' : '' ?>
706-
data-link-type="<?php echo esc_attr( $option_key ) ?>"
707-
data-field-key="<?php echo esc_attr( $field_key ) ?>"
708-
>
709-
<span style="margin: 0 5px 1rem 0;"><?php dt_render_field_icon( $option_value ) ?></span>
710-
<?php echo esc_html( $option_value['label'] ) ?>
711-
</div>
712-
713-
<?php endforeach; ?>
714-
</div>
715-
</div>
716-
717-
<?php endif; ?>
718-
</div>
719-
<?php endif; ?>
720669
<?php
721670
// render fields
722671
if ( $field_type === 'boolean' ):
@@ -736,62 +685,6 @@ class="add-link__option"
736685
class="text-input" value="<?php echo esc_html( $post[$field_key] ?? '' ) ?>" <?php echo esc_html( $disabled ); ?>
737686
min="<?php echo esc_html( $fields[$field_key]['min_option'] ?? '' ) ?>"
738687
max="<?php echo esc_html( $fields[$field_key]['max_option'] ?? '' ) ?>" onwheel="return false;" />
739-
<?php elseif ( $field_type === 'link' ): ?>
740-
741-
<div class="link-group">
742-
743-
<div class="link-list-<?php echo esc_attr( $field_key ) ?>">
744-
745-
<?php
746-
$links_sorted_by_type = [];
747-
foreach ( $post[$field_key] ?? [] as $link_item ) {
748-
if ( !isset( $link_item['type'] ) ) {
749-
continue;
750-
}
751-
$link_type = $link_item['type'];
752-
if ( !isset( $links_sorted_by_type[$link_type] ) ) {
753-
$links_sorted_by_type[$link_type] = [];
754-
}
755-
$links_sorted_by_type[$link_type][] = $link_item;
756-
}
757-
758-
$only_one_option = count( $fields[$field_key]['default'] ) === 1;
759-
foreach ( $fields[$field_key]['default'] as $link_type => $link_value ) : ?>
760-
761-
<div class="link-section link-section--<?php echo esc_attr( $link_type ) ?>">
762-
<div class="section-subheader" <?php echo $only_one_option ? 'style="display: none"' : '' ?> >
763-
<?php dt_render_field_icon( $link_value ) ?>
764-
<?php echo esc_html( $link_value['label'] ); ?>
765-
</div>
766-
767-
<?php if ( isset( $links_sorted_by_type[$link_type] ) ) : ?>
768-
<?php foreach ( $links_sorted_by_type[$link_type] as $link_item ) : ?>
769-
770-
<?php render_link_field( $field_key, $link_type, $link_item['value'], $display_field_id, $link_item['meta_id'], $required_tag, $disabled ); ?>
771-
772-
<?php endforeach; ?>
773-
<?php endif; ?>
774-
775-
</div>
776-
777-
<?php endforeach; ?>
778-
779-
</div>
780-
781-
<?php foreach ( $fields[$field_key]['default'] as $option_key => $option_value ): ?>
782-
783-
<?php if ( isset( $option_value['deleted'] ) && $option_value['deleted'] === true ) {
784-
continue;
785-
} ?>
786-
787-
<div style="display: none" id="link-template-<?php echo esc_html( $field_key ) ?>-<?php echo esc_html( $option_key ) ?>">
788-
<?php render_link_field( $field_key, $option_key, '', $display_field_id, '', $required_tag, $disabled ) ?>
789-
</div>
790-
791-
<?php endforeach; ?>
792-
793-
</div>
794-
795688
<?php elseif ( $field_type === 'datetime' ): ?>
796689
<?php $timestamp = $post[$field_key]['timestamp'] ?? '' ?>
797690
<div class="<?php echo esc_html( $display_field_id ); ?> input-group dt_date_time_group" data-timestamp="<?php echo esc_html( $timestamp ) ?>">
@@ -834,34 +727,6 @@ class="text-input" value="<?php echo esc_html( $post[$field_key] ?? '' ) ?>" <?p
834727
do_action( 'dt_render_field_for_display_template', $post, $field_type, $field_key, $required_tag, $display_field_id, $custom_display, $fields );
835728
}
836729

837-
function render_link_field( $field_key, $option_key, $value, $display_field_id, $meta_id, $required_tag, $disabled ) {
838-
?>
839-
840-
<div class="input-group">
841-
<input
842-
type="text"
843-
class="link-input input-group-field"
844-
value="<?php echo esc_html( $value ) ?>"
845-
data-meta-id="<?php echo esc_html( $meta_id ) ?>"
846-
data-field-key="<?php echo esc_html( $display_field_id ) ?>"
847-
data-type="<?php echo esc_html( $option_key ) ?>"
848-
<?php echo esc_html( $required_tag ) ?>
849-
<?php echo esc_html( $disabled ) ?>
850-
>
851-
<div class="input-group-button">
852-
<button
853-
class="button alert delete-button-style input-height link-delete-button delete-button"
854-
data-meta-id="<?php echo esc_html( $meta_id ) ?>"
855-
data-field-key="<?php echo esc_html( $field_key ) ?>"
856-
>
857-
&times;
858-
</button>
859-
</div>
860-
</div>
861-
862-
<?php
863-
}
864-
865730
function dt_increment( &$var, $val ){
866731
if ( !isset( $var ) ){
867732
$var = 0;

dt-core/utilities/dt-components.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,14 @@ public static function render_user_select( $field_key, $fields, $post, $params =
321321
</dt-users-connection>
322322
<?php
323323
}
324+
325+
public static function render_link( $field_key, $fields, $post, $params = [] ) {
326+
$shared_attributes = self::shared_attributes( $field_key, $fields, $post, $params );
327+
?>
328+
<dt-multi-text-groups <?php echo wp_kses_post( $shared_attributes ) ?>
329+
value="<?php echo esc_attr( isset( $post[$field_key] ) ? json_encode( $post[$field_key] ) : '' ) ?>">
330+
<?php dt_render_icon_slot( $fields[$field_key] ) ?>
331+
</dt-multi-text-groups>
332+
<?php
333+
}
324334
}

0 commit comments

Comments
 (0)