| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template: Flexible Content — single row. |
| 4 |
* |
| 5 |
* Used by both the live rows and the hidden JS-clone templates. |
| 6 |
* |
| 7 |
* @var array<string, mixed> $settings Field configuration. |
| 8 |
* @var string $layout Layout type key. |
| 9 |
* @var array<string, mixed> $layout_config Layout configuration (title, fields, etc.). |
| 10 |
* @var int $option_key Row index. |
| 11 |
* @var array<string, mixed> $option Row values. |
| 12 |
* @var bool $has_sorting Whether sorting is enabled. |
| 13 |
* @var bool $has_accordion Whether accordion is enabled. |
| 14 |
* @var bool $is_clone Whether this is a clone template (uses data-name instead of name). |
| 15 |
* @var bool $deferred Whether this row should use deferred rendering (lazy load). |
| 16 |
* @var string $module_id Module ID. |
| 17 |
* @var Merchant_Field_Flexible_Content $field The field instance. |
| 18 |
* |
| 19 |
* @package Merchant |
| 20 |
* @since 2.2.5 |
| 21 |
*/ |
| 22 |
|
| 23 |
if ( ! defined( 'ABSPATH' ) ) { |
| 24 |
exit; |
| 25 |
} |
| 26 |
|
| 27 |
$deferred = ! empty( $deferred ); |
| 28 |
$title_field = $layout_config['title-field'] ?? ''; |
| 29 |
$row_title = $is_clone ? ( $layout_config['title'] ?? '' ) : ( $option[ $title_field ] ?? '' ); |
| 30 |
$count = $is_clone ? 1 : absint( $option_key + 1 ); |
| 31 |
$status_field = $layout_config['status-field'] ?? ''; |
| 32 |
$status_value = ''; |
| 33 |
|
| 34 |
if ( ! empty( $status_field ) ) { |
| 35 |
if ( $is_clone ) { |
| 36 |
// Clone template: default value will be set via JS on add/duplicate. |
| 37 |
$status_value = 'active'; |
| 38 |
} else { |
| 39 |
$status_value = $option[ $status_field ] ?? 'active'; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
$name_attr = $is_clone ? 'data-name' : 'name'; |
| 44 |
?> |
| 45 |
<div class="layout" data-type="<?php echo esc_attr( $layout ) ?>"<?php |
| 46 |
if ( ! $is_clone && ! empty( $option['flexible_id'] ) ) { |
| 47 |
echo ' data-layout-id="' . esc_attr( $option['flexible_id'] ) . '"'; |
| 48 |
} |
| 49 |
if ( $deferred ) { |
| 50 |
echo ' data-deferred="1"'; |
| 51 |
$deferred_data = $field->build_deferred_data( $layout_config['fields'] ?? array(), $option ); |
| 52 |
$json = wp_json_encode( $deferred_data ); |
| 53 |
echo ' data-fields-json="' . esc_attr( $json ? $json : '{}' ) . '"'; |
| 54 |
} |
| 55 |
?>> |
| 56 |
<div class="layout__inner"> |
| 57 |
<?php if ( $has_sorting ) : ?> |
| 58 |
<span class="customize-control-flexible-content-move"> |
| 59 |
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="14" viewBox="0 0 10 14" fill="none"> |
| 60 |
<path d="M1.75 0.5C1.19772 0.5 0.75 0.947715 0.75 1.5V2.5C0.75 3.05228 1.19772 3.5 1.75 3.5H2.75C3.30228 3.5 3.75 3.05228 3.75 2.5V1.5C3.75 0.947715 3.30228 0.5 2.75 0.5H1.75Z" fill="#4A4A4A"/> |
| 61 |
<path d="M1.75 5.5C1.19772 5.5 0.75 5.94772 0.75 6.5V7.5C0.75 8.05228 1.19772 8.5 1.75 8.5H2.75C3.30228 8.5 3.75 8.05228 3.75 7.5V6.5C3.75 5.94772 3.30228 5.5 2.75 5.5H1.75Z" fill="#4A4A4A"/> |
| 62 |
<path d="M0.75 11.5C0.75 10.9477 1.19772 10.5 1.75 10.5H2.75C3.30228 10.5 3.75 10.9477 3.75 11.5V12.5C3.75 13.0523 3.30228 13.5 2.75 13.5H1.75C1.19772 13.5 0.75 13.0523 0.75 12.5V11.5Z" fill="#4A4A4A"/> |
| 63 |
<path d="M7.25 0.5C6.69772 0.5 6.25 0.947715 6.25 1.5V2.5C6.25 3.05228 6.69772 3.5 7.25 3.5H8.25C8.80228 3.5 9.25 3.05228 9.25 2.5V1.5C9.25 0.947715 8.80228 0.5 8.25 0.5H7.25Z" fill="#4A4A4A"/> |
| 64 |
<path d="M6.25 6.5C6.25 5.94772 6.69772 5.5 7.25 5.5H8.25C8.80228 5.5 9.25 5.94772 9.25 6.5V7.5C9.25 8.05228 8.80228 8.5 8.25 8.5H7.25C6.69772 8.5 6.25 8.05228 6.25 7.5V6.5Z" fill="#4A4A4A"/> |
| 65 |
<path d="M7.25 10.5C6.69772 10.5 6.25 10.9477 6.25 11.5V12.5C6.25 13.0523 6.69772 13.5 7.25 13.5H8.25C8.80228 13.5 9.25 13.0523 9.25 12.5V11.5C9.25 10.9477 8.80228 10.5 8.25 10.5H7.25Z" fill="#4A4A4A"/> |
| 66 |
</svg> |
| 67 |
</span> |
| 68 |
<?php endif; ?> |
| 69 |
<div class="layout-header"> |
| 70 |
<div class="layout-count"><?php echo absint( $count ) ?></div> |
| 71 |
<div class="layout-title"<?php |
| 72 |
if ( ! empty( $title_field ) ) { |
| 73 |
echo ' data-title-field="' . esc_attr( $title_field ) . '"'; |
| 74 |
} ?>> |
| 75 |
<?php echo esc_html( $row_title ); ?> |
| 76 |
</div> |
| 77 |
<?php if ( ! empty( $status_field ) ) : |
| 78 |
// Resolve the field's option keys for JS deferred toggle. |
| 79 |
$status_options = array(); |
| 80 |
if ( ! empty( $layout_config['fields'] ) ) { |
| 81 |
foreach ( $layout_config['fields'] as $sub_field ) { |
| 82 |
if ( isset( $sub_field['id'] ) && $sub_field['id'] === $status_field && ! empty( $sub_field['options'] ) ) { |
| 83 |
$status_options = array_keys( $sub_field['options'] ); |
| 84 |
break; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
?> |
| 89 |
<span class="layout-status layout-status--<?php echo esc_attr( $status_value ); ?>" |
| 90 |
data-status-field="<?php echo esc_attr( $status_field ); ?>" |
| 91 |
<?php if ( ! empty( $status_options ) ) : ?> |
| 92 |
data-status-options="<?php echo esc_attr( implode( ',', $status_options ) ); ?>" |
| 93 |
<?php endif; ?>> |
| 94 |
<?php echo esc_html( ucfirst( $status_value ) ); ?> |
| 95 |
</span> |
| 96 |
<?php endif; ?> |
| 97 |
<div class="layout-toggle"> |
| 98 |
<?php if ( $has_accordion ) : ?> |
| 99 |
<span class="customize-control-flexible-content-accordion"> |
| 100 |
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="7" viewBox="0 0 10 7" fill="none"> |
| 101 |
<path fill-rule="evenodd" clip-rule="evenodd" d="M0.71967 0.732854C1.01256 0.43996 1.48744 0.43996 1.78033 0.732854L5.25 4.20252L8.71967 0.732854C9.01256 0.43996 9.48744 0.43996 9.78033 0.732854C10.0732 1.02575 10.0732 1.50062 9.78033 1.79351L5.78033 5.79351C5.48744 6.08641 5.01256 6.08641 4.71967 5.79351L0.71967 1.79351C0.426777 1.50062 0.426777 1.02575 0.71967 0.732854Z" fill="#4A4A4A"/> |
| 102 |
</svg> |
| 103 |
</span> |
| 104 |
<?php endif; ?> |
| 105 |
</div> |
| 106 |
</div> |
| 107 |
<div class="layout-body"> |
| 108 |
<?php if ( ! $deferred ) : ?> |
| 109 |
<?php |
| 110 |
foreach ( $layout_config['fields'] as $sub_field ) : |
| 111 |
$classes = array( 'layout-field' ); |
| 112 |
if ( isset( $sub_field['classes'] ) ) { |
| 113 |
$classes = array_merge( $classes, $sub_field['classes'] ); |
| 114 |
} ?> |
| 115 |
<div class="<?php echo esc_attr( implode( ' ', $classes ) ) ?>"> |
| 116 |
<?php |
| 117 |
if ( $is_clone ) { |
| 118 |
// Clone template: use defaults and data-name attributes. |
| 119 |
if ( 'fields_group' === $sub_field['type'] ) { |
| 120 |
Merchant_Field_Fields_Group::render_group( $sub_field, $option, $module_id, true, array( |
| 121 |
'id' => $settings['id'], |
| 122 |
'option_key' => 0, |
| 123 |
'value' => $option, |
| 124 |
) ); |
| 125 |
} else { |
| 126 |
Merchant_Field_Flexible_Content::render_sub_field( |
| 127 |
$sub_field, |
| 128 |
$sub_field['default'] ?? '', |
| 129 |
array( |
| 130 |
"name=\"merchant[{$sub_field['id']}]", |
| 131 |
'merchant-module-page-setting-field-upload', |
| 132 |
'merchant-module-page-setting-field-select_ajax', |
| 133 |
), |
| 134 |
array( |
| 135 |
"data-name=\"merchant[{$settings['id']}][0][{$sub_field['id']}]", |
| 136 |
'merchant-module-page-setting-field-upload template', |
| 137 |
'merchant-module-page-setting-field-select_ajax template', |
| 138 |
), |
| 139 |
$module_id |
| 140 |
); |
| 141 |
} |
| 142 |
} else { |
| 143 |
// Live row: use actual values and name attributes. |
| 144 |
$sub_value = null; |
| 145 |
if ( isset( $option[ $sub_field['id'] ] ) ) { |
| 146 |
$sub_value = $option[ $sub_field['id'] ]; |
| 147 |
} elseif ( isset( $sub_field['default'] ) ) { |
| 148 |
$sub_value = $sub_field['default']; |
| 149 |
} elseif ( isset( $sub_field['type'] ) && $sub_field['type'] === 'switcher' ) { |
| 150 |
$sub_value = 0; |
| 151 |
} |
| 152 |
|
| 153 |
if ( 'fields_group' === $sub_field['type'] ) { |
| 154 |
Merchant_Field_Fields_Group::render_group( $sub_field, $sub_value, $module_id, true, array( |
| 155 |
'id' => $settings['id'], |
| 156 |
'option_key' => $option_key, |
| 157 |
'value' => $option, |
| 158 |
) ); |
| 159 |
} else { |
| 160 |
Merchant_Field_Flexible_Content::render_sub_field( |
| 161 |
$sub_field, |
| 162 |
$sub_value, |
| 163 |
"name=\"merchant[{$sub_field['id']}]", |
| 164 |
"name=\"merchant[{$settings['id']}][{$option_key}][{$sub_field['id']}]", |
| 165 |
$module_id |
| 166 |
); |
| 167 |
} |
| 168 |
} |
| 169 |
?> |
| 170 |
</div> |
| 171 |
<?php endforeach; ?> |
| 172 |
<?php endif; ?> |
| 173 |
<input type="hidden" <?php echo esc_attr( $name_attr ); ?>="merchant[<?php echo esc_attr( $settings['id'] ) ?>][<?php echo absint( $option_key ) ?>][layout]" |
| 174 |
value="<?php echo esc_attr( $layout ) ?>"> |
| 175 |
<input type="hidden" class="flexible-id" <?php echo esc_attr( $name_attr ); ?>="merchant[<?php echo esc_attr( $settings['id'] ) ?>][<?php echo absint( $option_key ) ?>][flexible_id]" value="<?php |
| 176 |
echo isset( $option['flexible_id'] ) ? esc_attr( $option['flexible_id'] ) : '' ?>"> |
| 177 |
</div> |
| 178 |
<?php |
| 179 |
$field->get_template_part( 'actions', array( |
| 180 |
'layout_type' => $layout, |
| 181 |
'has_duplicate' => ! empty( $settings['duplicate'] ), |
| 182 |
'has_accordion' => ! empty( $settings['accordion'] ), |
| 183 |
) ); |
| 184 |
?> |
| 185 |
</div> |
| 186 |
</div> |
| 187 |
|