From 597a8f4e80f1523737c879ec0be85901348d9f70 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Fri, 22 Sep 2023 01:01:58 +0200 Subject: [PATCH] allow is_active field to default to '0' --- Civi/Api4/Service/Spec/SpecGatherer.php | 3 --- tests/phpunit/api/v4/Spec/SpecGathererTest.php | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Civi/Api4/Service/Spec/SpecGatherer.php b/Civi/Api4/Service/Spec/SpecGatherer.php index 0e5225723d..d77e3a8bc4 100644 --- a/Civi/Api4/Service/Spec/SpecGatherer.php +++ b/Civi/Api4/Service/Spec/SpecGatherer.php @@ -97,9 +97,6 @@ class SpecGatherer extends AutoService { if (!empty($DAOField['component']) && !\CRM_Core_Component::isEnabled($DAOField['component'])) { continue; } - if ($DAOField['name'] == 'is_active' && empty($DAOField['default'])) { - $DAOField['default'] = '1'; - } $this->setDynamicFk($DAOField, $values); $field = SpecFormatter::arrayToField($DAOField, $entityName); $spec->addFieldSpec($field); diff --git a/tests/phpunit/api/v4/Spec/SpecGathererTest.php b/tests/phpunit/api/v4/Spec/SpecGathererTest.php index 04de1c46a4..f879af8c18 100644 --- a/tests/phpunit/api/v4/Spec/SpecGathererTest.php +++ b/tests/phpunit/api/v4/Spec/SpecGathererTest.php @@ -65,4 +65,11 @@ class SpecGathererTest extends Api4TestBase { $this->assertContains('foo', $fieldNames); } + public function testIsActiveFieldCanDefaultToFalse(): void { + $gatherer = new SpecGatherer(); + // Use Dashboard as it has is_active field and that defaults to 0 (according to schema) + $specs = $gatherer->getSpec('Dashboard', 'create', FALSE); + self::assertFalse($specs->getFieldByName('is_active')->getDefaultValue(), 'Default value for "is_active" field is not false'); + } + } -- 2.25.1