Skip to content

Commit b48cdb0

Browse files
committed
Support duplicating groups of fields
Auto rebuild assets DFV work for duplicate group Separate the duplicate group endpoint Remove temp debug Auto rebuild assets
1 parent 6c61ed6 commit b48cdb0

14 files changed

+404
-72
lines changed

classes/PodsAPI.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6632,6 +6632,7 @@ public function duplicate_pod( $params, $strict = false ) {
66326632
* $params['id'] int The Group ID.
66336633
* $params['name'] string The Group name.
66346634
* $params['new_name'] string The new Group name.
6635+
* $params['duplicate_fields'] bool Whether to duplicate the fields.
66356636
*
66366637
* @since 2.8.0
66376638
*
@@ -6670,7 +6671,11 @@ public function duplicate_group( $params, $strict = false ) {
66706671
return false;
66716672
}
66726673

6674+
$pod_data = null;
6675+
66736676
if ( $group instanceof Group ) {
6677+
$pod_data = $group->get_parent_object();
6678+
66746679
$group = $group->export(
66756680
[
66766681
'include_fields' => true,
@@ -6701,7 +6706,13 @@ public function duplicate_group( $params, $strict = false ) {
67016706

67026707
$fields = $group['fields'];
67036708

6704-
unset( $group['id'], $group['parent'], $group['object_type'], $group['object_storage_type'], $group['fields'] );
6709+
unset( $group['id'], $group['object_type'], $group['object_storage_type'], $group['fields'] );
6710+
6711+
if ( $pod_data ) {
6712+
unset( $group['parent'] );
6713+
6714+
$group['pod_data'] = $pod_data;
6715+
}
67056716

67066717
try {
67076718
$group_id = $this->save_group( $group );
@@ -6715,16 +6726,24 @@ public function duplicate_group( $params, $strict = false ) {
67156726
return false;
67166727
}
67176728

6718-
foreach ( $fields as $field => $field_data ) {
6719-
unset( $field_data['id'], $field_data['parent'], $field_data['object_type'], $field_data['object_storage_type'], $field_data['group'] );
6729+
$group_data = $this->load_group( [ 'id' => $group_id ] );
67206730

6721-
$field_data['group_id'] = $group_id;
6731+
if ( ! empty( $params->duplicate_fields ) ) {
6732+
foreach ( $fields as $field_data ) {
6733+
try {
6734+
$field_params = [
6735+
'pod' => $pod_data,
6736+
'id' => $field_data['id'],
6737+
'name' => $field_data['name'],
6738+
'new_group' => $group_data,
6739+
'new_group_id' => $group_id,
6740+
];
67226741

6723-
try {
6724-
$this->save_field( $field_data );
6725-
} catch ( Exception $exception ) {
6726-
// Field not saved.
6727-
pods_debug_log( $exception );
6742+
$this->duplicate_field( $field_params, true || $strict );
6743+
} catch ( Exception $exception ) {
6744+
// Field not saved.
6745+
pods_debug_log( $exception );
6746+
}
67286747
}
67296748
}
67306749

src/Pods/REST/V1/Endpoints/Group.php

Lines changed: 0 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Pods/REST/V1/Endpoints/Group_Duplicate.php

Lines changed: 186 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Pods/REST/V1/Service_Provider.php

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/js/dfv/pods-dfv.min.asset.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"dependencies":["lodash","moment","react","react-dom","react-jsx-runtime","regenerator-runtime","wp-api-fetch","wp-autop","wp-components","wp-compose","wp-data","wp-element","wp-hooks","wp-i18n","wp-keycodes","wp-plugins","wp-primitives","wp-url"],"version":"d6321bc849a40e8533ec"}
1+
{"dependencies":["lodash","moment","react","react-dom","react-jsx-runtime","regenerator-runtime","wp-api-fetch","wp-autop","wp-components","wp-compose","wp-data","wp-element","wp-hooks","wp-i18n","wp-keycodes","wp-plugins","wp-primitives","wp-url"],"version":"dbd7cfddcb6a752a4019"}

ui/js/dfv/pods-dfv.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)