From bf6911f0fa6f5877337beea71bc42b55bd169803 Mon Sep 17 00:00:00 2001 From: colemanw Date: Sun, 1 Oct 2023 18:21:11 -0400 Subject: [PATCH] APIv4 - Trim output of Export action to only non-default values --- Civi/Api4/Generic/ExportAction.php | 6 ++++++ tests/phpunit/api/v4/Custom/ExportCustomGroupTest.php | 2 +- tests/phpunit/api/v4/Entity/ManagedEntityTest.php | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Civi/Api4/Generic/ExportAction.php b/Civi/Api4/Generic/ExportAction.php index d7903a70e6..13b660ec77 100644 --- a/Civi/Api4/Generic/ExportAction.php +++ b/Civi/Api4/Generic/ExportAction.php @@ -161,6 +161,12 @@ class ExportAction extends AbstractAction { unset($record[$fieldName]); } } + // Unset values that match the default + foreach ($allFields as $fieldName => $field) { + if (($record[$fieldName] ?? NULL) === $field['default_value']) { + unset($record[$fieldName]); + } + } $export = [ 'name' => $name, 'entity' => $entityType, diff --git a/tests/phpunit/api/v4/Custom/ExportCustomGroupTest.php b/tests/phpunit/api/v4/Custom/ExportCustomGroupTest.php index 429b4dffb6..e36d3ba8b8 100644 --- a/tests/phpunit/api/v4/Custom/ExportCustomGroupTest.php +++ b/tests/phpunit/api/v4/Custom/ExportCustomGroupTest.php @@ -66,7 +66,7 @@ class ExportCustomGroupTest extends CustomTestBase { // Should be only name, not id $this->assertArrayNotHasKey('option_group_id', $export[5]['params']['values']); // Field with no options - $this->assertNull($export[6]['params']['values']['option_group_id']); + $this->assertTrue(!isset($export[6]['params']['values']['option_group_id'])); $this->assertArrayNotHasKey('option_group_id.name', $export[6]['params']['values']); $this->assertArrayNotHasKey('option_values', $export[6]['params']['values']); } diff --git a/tests/phpunit/api/v4/Entity/ManagedEntityTest.php b/tests/phpunit/api/v4/Entity/ManagedEntityTest.php index 5aad9c475d..7c739a4e2d 100644 --- a/tests/phpunit/api/v4/Entity/ManagedEntityTest.php +++ b/tests/phpunit/api/v4/Entity/ManagedEntityTest.php @@ -410,7 +410,7 @@ class ManagedEntityTest extends TestCase implements HeadlessInterface, Transacti ->addChain('export', OptionGroup::export()->setId('$id')) ->execute()->first(); $this->assertEquals('from_email_address', $result['export'][1]['params']['values']['option_group_id.name']); - $this->assertNull($result['export'][1]['params']['values']['visibility_id']); + $this->assertArrayNotHasKey('visibility_id', $result['export'][1]['params']['values']); $this->assertStringStartsWith('OptionGroup_from_email_address_OptionValue_', $result['export'][1]['name']); // All references should be from the current domain foreach (array_slice($result['export'], 1) as $reference) { -- 2.25.1